Function: todo-set-category-number

todo-set-category-number is an interactive and byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-set-category-number &optional ARG)

Documentation

Change number of category at point in the table of categories.

With ARG nil, prompt for the new number. Alternatively, the enter the new number with numerical prefix ARG. Otherwise, if ARG is either of the symbols raise or lower, raise or lower the category line in the table by one, respectively, thereby decreasing or increasing its number.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-set-category-number (&optional arg)
  "Change number of category at point in the table of categories.

With ARG nil, prompt for the new number.  Alternatively, the
enter the new number with numerical prefix ARG.  Otherwise, if
ARG is either of the symbols `raise' or `lower', raise or lower
the category line in the table by one, respectively, thereby
decreasing or increasing its number."
  (interactive "P")
  (let ((curnum (save-excursion
		  ;; Get the number representing the priority of the category
		  ;; on the current line.
		  (forward-line 0) (skip-chars-forward " ") (number-at-point))))
    (when curnum		; Do nothing if we're not on a category line.
      (let* ((maxnum (length todo-categories))
	     (prompt (format "Set category priority (1-%d): " maxnum))
	     (col (current-column))
	     (buffer-read-only nil)
	     (priority (cond ((and (eq arg 'raise) (> curnum 1))
			      (1- curnum))
			     ((and (eq arg 'lower) (< curnum maxnum))
			      (1+ curnum))))
	     candidate)
	(while (not priority)
	  (setq candidate (or arg (read-number prompt)))
	  (setq arg nil)
	  (setq prompt
		(cond ((or (< candidate 1) (> candidate maxnum))
		       (format "Priority must be an integer between 1 and %d: "
			       maxnum))
		      ((= candidate curnum)
		       "Choose a different priority than the current one: ")))
	  (unless prompt (setq priority candidate)))
	(let* ((lower (< curnum priority)) ; Priority is being lowered.
	       (head (butlast todo-categories
			      (funcall (if lower #'identity #'1+)
                                       (- maxnum priority))))
	       (tail (nthcdr (funcall (if lower #'identity #'1-) priority)
			     todo-categories))
	       ;; Category's name and items counts list.
	       (catcons (nth (1- curnum) todo-categories))
	       (todo-categories (nconc head (list catcons) tail))
	       newcats)
	  (when lower (setq todo-categories (nreverse todo-categories)))
	  (setq todo-categories (delete-dups todo-categories))
	  (when lower (setq todo-categories (nreverse todo-categories)))
	  (setq newcats todo-categories)
	  (kill-buffer)
	  (with-current-buffer (find-buffer-visiting todo-current-todo-file)
	    (setq todo-categories newcats)
	    (todo-update-categories-sexp))
	  (todo-show-categories-table)
	  (forward-line (1+ priority))
	  (forward-char col))))))