# HG changeset patch # User Roland Winkler # Date 1229296478 0 # Node ID 586161dec886bf1d427976144ad9181eab6fdff5 # Parent 0c0c8f782b732207ca6f9e47e4a2eb0b7057c98b (proced-sort-interactive, proced-sort-pcpu) (proced-sort-pmem, proced-sort-start, proced-sort-time) (proced-sort-user, proced-sort-header): Prefix arg determines sorting order. Suggested by Dan Nicolaescu. (proced-revert): Doc fix. diff -r 0c0c8f782b73 -r 586161dec886 lisp/proced.el --- a/lisp/proced.el Sun Dec 14 17:41:29 2008 +0000 +++ b/lisp/proced.el Sun Dec 14 23:14:38 2008 +0000 @@ -345,6 +345,9 @@ ;; Internal variables +(defvar proced-available (not (null (list-system-processes))) + "Non-nil means Proced is known to work on this system.") + (defvar proced-process-alist nil "Alist of processes displayed by Proced. The car of each element is the PID, and the cdr is a list of @@ -592,10 +595,7 @@ to change the sort scheme. The current sort scheme is indicated in the mode line, using \"+\" or \"-\" for ascending or descending sort order. -An existing Proced listing can be refined by typing \\[proced-refine] -with point on the attribute of a process. If point is on the attribute ATTR, -this compares the value of ATTR of every process with the value of ATTR -of the process at the position of point. See `proced-refine' for details. +An existing Proced listing can be refined by typing \\[proced-refine]. Refining an existing listing does not update the variable `proced-filter'. The attribute-specific rules for formatting, filtering, sorting, and refining @@ -619,9 +619,6 @@ ;; Proced mode is suitable only for specially formatted data. (put 'proced-mode 'mode-class 'special) -(defvar proced-available (not (null (list-system-processes))) - "Non-nil means Proced is known to work on this system.") - ;;;###autoload (defun proced (&optional arg) "Generate a listing of UNIX system processes. @@ -935,9 +932,9 @@ Refinement is controlled by the REFINER defined for each attribute ATTR in `proced-grammar-alist'. -If REFINER is a list of flags and point is on the attribute ATTR, this command -compares the value of ATTR of every process with the value of ATTR -of the process at the position of point. +If REFINER is a list of flags and point is on a process's value of ATTR, +this command compares the value of ATTR of every process with the value +of ATTR of the process at the position of point. The predicate for the comparison of two ATTR values is defined in `proced-grammar-alist'. For each return value of the predicate @@ -1073,12 +1070,16 @@ (sort process-alist 'proced-sort-p)) process-alist)) -(defun proced-sort-interactive (scheme &optional revert) +(defun proced-sort-interactive (scheme &optional arg) "Sort Proced buffer using SCHEME. When called interactively, an empty string means nil, i.e., no sorting. -With prefix REVERT non-nil revert listing. -Repeated calls using the same value of SCHEME toggle the sort order. +Prefix ARG controls sort order: +- If prefix ARG is positive (negative), sort in ascending (descending) order. +- If ARG is nil or 'no-arg and SCHEME is equal to the previous sorting scheme, + reverse the sorting order. +- If ARG is nil or 'no-arg and SCHEME differs from the previous sorting scheme, + adopt the sorting order defined for SCHEME in `proced-grammar-alist'. Set variable `proced-sort' to SCHEME. The current sort scheme is displayed in the mode line, using \"+\" or \"-\" for ascending or descending order." @@ -1086,60 +1087,68 @@ (let ((scheme (completing-read "Sort attribute: " proced-grammar-alist nil t))) (list (if (string= "" scheme) nil (intern scheme)) - current-prefix-arg))) - (setq proced-descend - ;; If `proced-sort-interactive' is called repeatedly for the same sort key, - ;; the sort order is reversed. - (if (equal proced-sort scheme) - (not proced-descend) - (nth 5 (assq (if (consp scheme) (car scheme) scheme) - proced-grammar-alist))) - proced-sort scheme) - (proced-update revert)) + ;; like 'toggle in `define-derived-mode' + (or current-prefix-arg 'no-arg)))) -(defun proced-sort-pcpu (&optional revert) - "Sort Proced buffer by percentage CPU time (%CPU). -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'pcpu revert)) + (setq proced-descend + ;; If `proced-sort-interactive' is called repeatedly for the same + ;; sort key, the sort order is reversed. + (cond ((and (eq arg 'no-arg) (equal proced-sort scheme)) + (not proced-descend)) + ((eq arg 'no-arg) + (nth 5 (assq (if (consp scheme) (car scheme) scheme) + proced-grammar-alist))) + (arg (< (prefix-numeric-value arg) 0)) + ((equal proced-sort scheme) + (not proced-descend)) + (t (nth 5 (assq (if (consp scheme) (car scheme) scheme) + proced-grammar-alist)))) + proced-sort scheme) + (proced-update)) -(defun proced-sort-pmem (&optional revert) - "Sort Proced buffer by percentage memory usage (%MEM). -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'pmem revert)) +(defun proced-sort-pcpu (&optional arg) + "Sort Proced buffer by percentage CPU time (%CPU). +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'pcpu arg)) -(defun proced-sort-pid (&optional revert) - "Sort Proced buffer by PID. -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'pid revert)) +(defun proced-sort-pmem (&optional arg) + "Sort Proced buffer by percentage memory usage (%MEM). +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'pmem arg)) -(defun proced-sort-start (&optional revert) - "Sort Proced buffer by time the command started (START). -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'start revert)) +(defun proced-sort-pid (&optional arg) + "Sort Proced buffer by PID. +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'pid arg)) -(defun proced-sort-time (&optional revert) - "Sort Proced buffer by CPU time (TIME). -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'time revert)) +(defun proced-sort-start (&optional arg) + "Sort Proced buffer by time the command started (START). +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'start arg)) -(defun proced-sort-user (&optional revert) +(defun proced-sort-time (&optional arg) + "Sort Proced buffer by CPU time (TIME). +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'time arg)) + +(defun proced-sort-user (&optional arg) "Sort Proced buffer by USER. -Repeated calls toggle the sort order." - (interactive "P") - (proced-sort-interactive 'user revert)) +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg))) + (proced-sort-interactive 'user arg)) -(defun proced-sort-header (event &optional revert) +(defun proced-sort-header (event &optional arg) "Sort Proced listing based on an attribute. EVENT is a mouse event with starting position in the header line. It is converted in the corresponding attribute key. This command updates the variable `proced-sort'. -Repeated calls for the same header toggle the sort order." - (interactive "e\nP") +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list last-input-event (or last-prefix-arg 'no-arg))) (let ((start (event-start event)) col key) (save-selected-window @@ -1149,7 +1158,7 @@ (when (and (<= 0 col) (< col (length proced-header-line))) (setq key (get-text-property col 'proced-key proced-header-line)) (if key - (proced-sort-interactive key revert) + (proced-sort-interactive key arg) (message "No sorter defined here.")))))) ;;; Formating @@ -1491,7 +1500,8 @@ "Updating process display...done."))))) (defun proced-revert (&rest args) - "Analog of `revert-buffer'." + "Reevaluate the process listing based on the currently running processes. +Preserves point and marks." (proced-update t)) ;; I do not want to reinvent the wheel. Should we rename `dired-pop-to-buffer'