From: Roland Winkler Date: Mon, 14 Apr 2008 01:35:56 +0000 (+0000) Subject: (proced-command-alist): Remove sort column. X-Git-Tag: emacs-pretest-23.0.90~6291 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e6854b3fef49ac53e6aef1caecea6f749d70301e;p=emacs.git (proced-command-alist): Remove sort column. (proced-command, proced-procname-column): Use make-variable-buffer-local. (proced-signal-function): Renamed from proced-kill-program. Allow for elisp symbols and string values representing system calls. (proced-marker-regexp, proced-success-message): New functions. (proced): Use defalias. Add autoload cookie. (proced-unmark-backward, proced-toggle-marks) (proced-hide-processes): New commands. (proced-do-mark): Simplify code. (proced-insert-mark): Use optional arg BACKWARD instead of line number. (proced-update): Remove sorting. (proced-send-signal): Display number of processes to operate on. Allow for system calls or elisp functions to send signals. Check if signal was send successfully. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b6bf23ccbdc..f76b7cd5553 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,22 @@ +2008-04-13 Roland Winkler + + * proced.el (proced-command-alist): Remove sort column. + (proced-command, proced-procname-column): Use + make-variable-buffer-local. + (proced-signal-function): Renamed from proced-kill-program. Allow + for elisp symbols and string values representing system calls. + (proced-marker-regexp, proced-success-message): New functions. + (proced): Use defalias. Add autoload cookie. + (proced-unmark-backward, proced-toggle-marks) + (proced-hide-processes): New commands. + (proced-do-mark): Simplify code. + (proced-insert-mark): Use optional arg BACKWARD instead of line + number. + (proced-update): Remove sorting. + (proced-send-signal): Display number of processes to operate on. + Allow for system calls or elisp functions to send signals. Check + if signal was send successfully. + 2008-04-13 Stefan Monnier * minibuffer.el (completion-all-completion-with-base-size): New var. @@ -101,7 +120,7 @@ Move non-autoloaded define-obsolete-variable-alias calls for defcustoms not in dumped files before the associated defcustom. -2008-04-11 Johan BockgÃ¥rd +2008-04-11 Johan Bockgård * minibuffer.el (lazy-completion-table): Fix debug spec. @@ -152,7 +171,7 @@ * loadup.el: Load ldefs-boot.el if loaddefs.el doesn't exist. -2008-04-11 Jan Djärv +2008-04-11 Jan Djärv * tooltip.el (tooltip-show-help-non-mode): Set message-truncate-lines to t and don't truncate msg. @@ -328,7 +347,7 @@ * nxml/nxml-mode.el (nxml-cleanup): New function. (nxml-mode): Add it to change-major-mode-hook. -2008-04-09 Jan Djärv +2008-04-09 Jan Djärv * term/x-win.el (x-gtk-stock-map): Map info to gtk-info. @@ -336,7 +355,7 @@ * calc/.cvsignore: New file. -2008-04-09 Jan Djärv +2008-04-09 Jan Djärv * vc.el (vc-status-tool-bar-map): Add vc-print-log to tool bar. @@ -478,7 +497,7 @@ * faces.el (font-slant-table): Change numeric values for `r', `roman', and `normal'. -2008-04-07 Vincent Belaïche +2008-04-07 Vincent Belaïche * calc/calc-vec.el (calcFunc-kron, calc-kron): New functions. @@ -1548,7 +1567,7 @@ Likewise for braille and mathematical. Use unicode scripts that cover the phonetic script for IPA. -2008-04-01 Johan BockgÃ¥rd +2008-04-01 Johan Bockgård * emacs-lisp/cl-macs.el (frame-parameter) : Make it return the assigned value. @@ -1920,7 +1939,7 @@ (verilog-auto-unused, verilog-auto): Update documentation to use more obvious instance module names versus cell names. -2008-03-28 Jan Djärv +2008-03-28 Jan Djärv * progmodes/compile.el (compilation-mode-tool-bar-map): Only enable kill if a process is running. @@ -2019,7 +2038,7 @@ * image-mode.el (image-mode-reapply-winprops): Simplify now that window-configuration-change-hook works buffer-locally. -2008-03-26 Johan BockgÃ¥rd +2008-03-26 Johan Bockgård * emacs-lisp/lisp-mnt.el (lm-with-file): Use mode and syntax table for Emacs Lisp, not Lisp. @@ -2032,7 +2051,7 @@ * emacs-lisp/bytecomp.el (byte-compile-obsolete): If no replacement is provided, don't print "use nil instead". -2008-03-26 Johan BockgÃ¥rd +2008-03-26 Johan Bockgård * complete.el (PC-do-completion): Use regexp-quote. @@ -2173,7 +2192,7 @@ (verilog-signals-matching-regexp): New internal function for signal matching. -2008-03-25 Johan BockgÃ¥rd +2008-03-25 Johan Bockgård * info.el (Info-isearch-search): Always return point. @@ -2610,7 +2629,7 @@ * international/mule.el (load-with-code-conversion): Avoid setting default-enable-multibyte-characters. -2008-03-19 Gustav HÃ¥llberg (tiny change) +2008-03-19 Gustav Hållberg (tiny change) * vc.el (vc-annotate-background): Fix custom type. @@ -3173,7 +3192,7 @@ * progmodes/sh-script.el (sh-font-lock-quoted-subshell): Fix handling of \ and '. -2008-03-13 Johan BockgÃ¥rd +2008-03-13 Johan Bockgård * net/browse-url.el (browse-url-text-xterm): Unquote browse-url-text-browser. @@ -3661,7 +3680,7 @@ (bookmark-insert-buffer-name): Remove. (bookmark-buffer-file-name): Signal an error rather than returning nil. -2008-03-09 Thomas Hühn (tiny change) +2008-03-09 Thomas Hühn (tiny change) * tutorial.el (tutorial--default-keys): Update `C-l' binding. @@ -3726,7 +3745,7 @@ (bookmark-prop-get): Declare. (Info-bookmark-jump): Use it. -2008-03-08 Johan BockgÃ¥rd +2008-03-08 Johan Bockgård * subr.el (while-no-input): Don't splice BODY directly into the `or' form. @@ -3930,7 +3949,7 @@ * image-mode.el (image-bookmark-make-record): * info.el (Info-bookmark-make-record): Delete obsolete second arg. -2008-03-07 Jan Djärv +2008-03-07 Jan Djärv * vc.el (vc-status-menu-map-filter): Return orig-binding if boundp 'vc-ignore-menu-filter. @@ -4080,7 +4099,7 @@ (org-promote, org-demote, org-archive-subtree) (org-remember-handler, org-refile, org-put-clock-overlay): Use it. -2008-03-06 Jan Djärv +2008-03-06 Jan Djärv * term/x-win.el (x-gtk-stock-map): Add bookmark_add. @@ -4577,7 +4596,7 @@ when using transient-mark-mode. (default-indicate-unused-lines): Remove unused var. -2008-02-26 Jan Djärv +2008-02-26 Jan Djärv * progmodes/grep.el (grep-mode-tool-bar-map): Change place on next and previous. @@ -4647,7 +4666,7 @@ * help-mode.el (help-info-variable): New button able to read Info files for help-fns.el. -2008-02-25 Jan Djärv +2008-02-25 Jan Djärv * progmodes/grep.el (grep-mode-tool-bar-map): New variable. (grep-mode): Use grep-mode-tool-bar-map. @@ -4884,7 +4903,7 @@ * font-lock.el (font-lock-set-defaults): Unset previously set variables when needed. -2008-02-24 Ævar Arnfjörð Bjarmason (tiny change) +2008-02-24 Ævar Arnfjörð Bjarmason (tiny change) * net/rcirc.el (rcirc-url-regexp): Replace definition by copying from gnus-button-url-regexp. @@ -5460,7 +5479,7 @@ * startup.el (command-line): Use custom-reevaluate-setting for transient-mark-mode. -2008-02-17 Michaël Cadilhac +2008-02-17 Michaël Cadilhac * wdired.el (wdired-allow-to-change-permissions): Fix typo. @@ -7610,7 +7629,7 @@ 2008-02-01 Dave Love * international/mule-diag.el (describe-character-set): - Fix printing dimensions. Use `×', not `x'. + Fix printing dimensions. Use `×', not `x'. 2008-02-01 Kenichi Handa @@ -8057,7 +8076,7 @@ 2008-02-01 Dave Love - * international/characters.el: Make Ÿ and ÿ a case pair. + * international/characters.el: Make Ÿ and ÿ a case pair. 2008-02-01 Kenichi Handa @@ -11994,7 +12013,7 @@ * progmodes/python.el (top-level): Don't require cl when compiling. -2007-12-02 Agustín Martín +2007-12-02 Agustín Martín * textmodes/flyspell.el (flyspell-large-region): Explicitly set encoding for aspell process and for communication with it. @@ -12738,7 +12757,7 @@ (x-send-client-message): * emulation/cua-base.el (x-clipboard-yank): Declare as functions. -2007-11-22 Jan Djärv +2007-11-22 Jan Djärv * term/x-win.el (x-gtk-map-stock): Check if FILE is a string. @@ -13651,7 +13670,7 @@ * emulation/tpu-mapper.el (tpu-map-key): Remove un-needed cond branch. -2007-11-07 Johan BockgÃ¥rd +2007-11-07 Johan Bockgård * eshell/esh-mode.el (eshell-output-filter): * eshell/esh-proc.el (eshell-insertion-filter, eshell-sentinel): @@ -15318,7 +15337,7 @@ * help-fns.el (describe-function-1): Don't use the advice origname if it has no function definition. -2007-10-18 Johan BockgÃ¥rd +2007-10-18 Johan Bockgård * net/tramp.el (tramp-rfn-eshadow-update-overlay): Save excursion. Use `save-restriction' rather than `widen'. @@ -16021,7 +16040,7 @@ (bs--get-mode-name, bs-mode): Fix typos in docstrings. (bs--format-aux): Doc fix. -2007-10-08 Michaël Cadilhac +2007-10-08 Michaël Cadilhac * progmodes/gud.el (gud-gud-gdb-command-name): Fix typo in docstring. @@ -16067,11 +16086,11 @@ * progmodes/gud.el (gud-display-line): Find source buffer even when GUD buffer has its own frame. -2007-10-08 Jan Djärv +2007-10-08 Jan Djärv * term/x-win.el (icon-map-list): Set to nil for 22.1 compatibility. -2007-10-08 Jan Djärv +2007-10-08 Jan Djärv * term/x-win.el (x-gtk-stock-map): Version is 22.2. @@ -16449,7 +16468,7 @@ * emacs-lisp/copyright.el (copyright-update): Don't update if the file already uses a more recent copyright version than the "current" one. -2007-10-03 Michaël Cadilhac +2007-10-03 Michaël Cadilhac * doc-view.el (doc-view-dvi->pdf-sentinel, doc-view-reset-slice) (doc-view-insert-image): Minor aesthetical docstring changes. @@ -16820,7 +16839,7 @@ * indent.el (indent-for-tab-command): First check if the region is active. -2007-09-24 Michaël Cadilhac +2007-09-24 Michaël Cadilhac * whitespace.el (whitespace-tickle-timer): Don't install the timer if whitespace-rescan-timer-time is 0. @@ -16940,7 +16959,7 @@ * indent.el (indent-for-tab-command): Indent the region if transient-mark-mode and the region is active. -2007-09-21 Francesco Potortì +2007-09-21 Francesco Potortì * progmodes/octave-inf.el (inferior-octave-mode): Use add-hook to add inferior-octave-directory-tracker to the buffer-local value @@ -17104,7 +17123,7 @@ (browse-url-elinks-sentinel): Use browse-url-elinks-new-window. Improve error message. -2007-09-19 Michaël Cadilhac +2007-09-19 Michaël Cadilhac * net/browse-url.el (browse-url-url-encode-chars): Use the right parameter name in the function body. @@ -17140,7 +17159,7 @@ * newcomment.el (comment-add): New arg EXTRA. (comment-region-default): Pass EXTRA if not indenting lines. -2007-09-17 Michaël Cadilhac +2007-09-17 Michaël Cadilhac * net/browse-url.el (browse-url-url-encode-chars): New function. URL-encode some chars in a string. @@ -17189,7 +17208,7 @@ (move-beginning-of-line): Remove unused var `start'. (blink-matching-open): Restructure in a more functional style. -2007-09-16 Michaël Cadilhac +2007-09-16 Michaël Cadilhac * calendar/holidays.el (list-holidays): Remove the cyclic alias. @@ -17347,7 +17366,7 @@ * term/rxvt.el (rxvt-function-map): Initialize in the declaration. -2007-09-12 Michaël Cadilhac +2007-09-12 Michaël Cadilhac * net/browse-url.el (browse-url-encode-url): Fix an infinite loop. New argument `filename-p' to use one set of confusing chars or another. @@ -17390,7 +17409,7 @@ 2007-09-10 Thien-Thi Nguyen * net/browse-url.el (browse-url-encode-url): Use copy-sequence. - Reported by Jan Djärv . + Reported by Jan Djärv . 2007-09-10 Dave Love @@ -17398,7 +17417,7 @@ Move font-lock-builtin-face down from 4 to 7 to better keep the progression of color brightness, and to better match Org-mode's faces. -2007-09-10 Michaël Cadilhac +2007-09-10 Michaël Cadilhac * progmodes/meta-mode.el (meta-font-lock-keywords) (font-lock-match-meta-declaration-item-and-skip-to-next) @@ -17566,7 +17585,7 @@ * vc-arch.el (vc-arch-checkin): Fix typo. -2007-09-07 Johan BockgÃ¥rd +2007-09-07 Johan Bockgård * cus-face.el (custom-theme-set-faces): Set face attributes locally for each frame. @@ -17635,7 +17654,7 @@ * complete.el (PC-do-completion): Don't try to treat empty string as an abbreviation. -2007-09-06 Johan BockgÃ¥rd +2007-09-06 Johan Bockgård * help-fns.el (describe-variable): Keep doc's text properties. @@ -17662,7 +17681,7 @@ (normal-no-mouse-startup-screen): New fn, broken out. (normal-about-screen): New function, contents all new. -2007-09-05 Michaël Cadilhac +2007-09-05 Michaël Cadilhac * emacs-lisp/rx.el (rx): Fix typo in docstring. @@ -17671,7 +17690,7 @@ * cus-edit.el (custom-buffer-create-internal): Check tool-bar-mode is bound. -2007-09-05 Johan BockgÃ¥rd +2007-09-05 Johan Bockgård * emacs-lisp/advice.el (ad-make-advised-docstring): Highlight note in doc string. @@ -17743,7 +17762,7 @@ (terminal-init-xterm): Use it. Deal with delete-frame hook. Add the selected frame to xterm-modify-other-keys-terminal-list. -2007-09-02 Jan Djärv +2007-09-02 Jan Djärv * term/x-win.el (x-gtk-stock-map): Map diropen to system-file-manager. (icon-map-list): New variable. @@ -17789,7 +17808,7 @@ * vc-svn.el (vc-svn-diff-tree): Pass a list to vc-svn-diff. -2007-08-31 Michaël Cadilhac +2007-08-31 Michaël Cadilhac * textmodes/flyspell.el (flyspell-mark-duplications-exceptions): New variable. List of exceptions for the duplicated word rule. @@ -17799,7 +17818,7 @@ * files.el (create-file-buffer): If the filename sans directory starts with spaces, remove them. -2007-08-31 Jan Djärv +2007-08-31 Jan Djärv * term/x-win.el (x-gtk-stock-map): Add etc/images to keys. (x-gtk-map-stock): Use two directory elements when matching @@ -17906,7 +17925,7 @@ * version.el (emacs-version): Increase to 23.0.50. -2007-08-29 Jan Djärv +2007-08-29 Jan Djärv * term/x-win.el (x-gtk-stock-map): :version changed to 23.1. @@ -17962,7 +17981,7 @@ * env.el (getenv): Pass frame to getenv-internal. -2007-08-29 Károly Lőrentey +2007-08-29 Károly LÅ‘rentey * version.el (emacs-version): Show if multi-tty is present. @@ -18263,7 +18282,7 @@ (display-time-world-timer-second, display-time-world-mode-map): New variables. -2007-08-28 Jan Djärv +2007-08-28 Jan Djärv * term/x-win.el (x-gtk-stock-map): New variable. (x-gtk-map-stock): New function. @@ -18271,7 +18290,7 @@ * info.el (info-tool-bar-map): Add :rtl keyword to right/left-arrow and prev/next-node. -2007-08-28 Johan BockgÃ¥rd (tiny change) +2007-08-28 Johan Bockgård (tiny change) * play/gamegrid.el (gamegrid-init): Set line-spacing to 0. @@ -18371,7 +18390,7 @@ * vc.el (vc-annotate-warp-version): Don't use previous-line. -2007-08-27 Johan BockgÃ¥rd +2007-08-27 Johan Bockgård * net/browse-url.el (browse-url-emacs): New function. @@ -18379,7 +18398,7 @@ * emacs-lisp/avl-tree.el: New file. -2007-08-26 Michaël Cadilhac +2007-08-26 Michaël Cadilhac * hi-lock.el (hi-lock-unface-buffer): Show a x-menu only if the mouse was used. @@ -18827,7 +18846,7 @@ undo-list when setting syntax-table properties. (ada-after-change-function): Use ada-set-syntax-table-properties. -2007-08-18 Michaël Cadilhac +2007-08-18 Michaël Cadilhac * progmodes/meta-mode.el (meta-indent-calculate-last): Remove. (meta-indent-current-nesting): Use a computation of the nesting @@ -18880,7 +18899,7 @@ (cperl-find-pods-heres): Fix an error when typing expressions like `s{a}{b}'. -2007-08-17 Michaël Cadilhac +2007-08-17 Michaël Cadilhac * mail/emacsbug.el (report-emacs-bug): Remove the last number of `emacs-version', use the topic prefix ``version; ''. Make MS-DOS @@ -18971,7 +18990,7 @@ sloppier, for the sake of GNU Mailman. (rmail-digest-rfc1153): Initialize `result' correctly. -2007-08-15 Michaël Cadilhac +2007-08-15 Michaël Cadilhac * mail/emacsbug.el (report-emacs-bug): Put `Bug: emacs-version; ' in the mail title. Suggested by Reiner Steib. @@ -20070,7 +20089,7 @@ * net/trampver.el: Update release number. -2007-07-22 Jan Djärv +2007-07-22 Jan Djärv * startup.el (command-line-x-option-alist): Use x-handle-no-bitmap-icon. @@ -20715,7 +20734,7 @@ * isearch.el (isearch-edit-string): Call to isearch-push-state after the search. -2007-07-09 Jan Djärv +2007-07-09 Jan Djärv * window.el (fit-window-to-buffer): Remove setting of window-min-height to 1 as enlarge-window uses the value to resize/shrink windows other @@ -21094,7 +21113,7 @@ * font-lock.el (lisp-font-lock-keywords-2): Recognize the new \(?1:..\) syntax as well. Reported by Juri Linkov . -2007-06-28 Jan Djärv +2007-06-28 Jan Djärv * dnd.el (dnd-get-local-file-name): Set fixcase to t in call to replace-regexp-in-string. @@ -21707,7 +21726,7 @@ * diff-mode.el (diff-font-lock-keywords): Fix M. Kifer's last change. -2007-06-13 Johan BockgÃ¥rd (tiny change) +2007-06-13 Johan Bockgård (tiny change) * term/xterm.el (terminal-init-xterm): Escape parens in character constants. @@ -21886,7 +21905,7 @@ * emacs-lisp/bytecomp.el (byte-compile-find-cl-functions): Match against file-name-nondirectory. Fix text on user customization variables. - Reported by Johan BockgÃ¥rd . + Reported by Johan Bockgård . 2007-06-09 Alfred M. Szmidt (tiny change) @@ -22284,7 +22303,7 @@ * files.el (set-auto-mode): Doc fix. -2007-05-22 Jan Djärv +2007-05-22 Jan Djärv * help-fns.el (find-source-lisp-file): New function. (describe-function-1): Use find-source-lisp-file to find source @@ -22492,7 +22511,7 @@ * dabbrev.el (dabbrev-eliminate-newlines): Renamed from dabbrev--eliminate-newlines. All uses changed. -2007-05-10 Michaël Cadilhac +2007-05-10 Michaël Cadilhac * man.el (Man-next-section): Don't consider the last line of the page as being part of any section. @@ -22675,7 +22694,7 @@ * image-dired.el (image-dired-display-image): Derive image-type from filename rather than assuming jpeg, in case no resizing was needed. -2007-04-25 Johan BockgÃ¥rd +2007-04-25 Johan Bockgård * custom.el (defface): Doc fix. diff --git a/lisp/proced.el b/lisp/proced.el index 6f2543ac9ac..9840d6f808f 100644 --- a/lisp/proced.el +++ b/lisp/proced.el @@ -1,4 +1,4 @@ -;;; proced.el --- operate on processes like dired +;;; proced.el --- operate on system processes like dired ;; Copyright (C) 2008 Free Software Foundation, Inc. @@ -24,18 +24,15 @@ ;;; Commentary: -;; Proced makes an Emacs buffer containing a listing of the current processes -;; (using ps(1)). You can use the normal Emacs commands to move around in -;; this buffer, and special Proced commands to operate on the processes listed. +;; Proced makes an Emacs buffer containing a listing of the current system +;; processes (using ps(1)). You can use the normal Emacs commands +;; to move around in this buffer, and special Proced commands to operate +;; on the processes listed. ;; -;; To autoload, use -;; (autoload 'proced "proced" nil t) -;; in your .emacs file. -;; -;; Is there a need for additional features like: -;; - automatic update of process list +;; To do: ;; - sort by CPU time or other criteria ;; - filter by user name or other criteria +;; - automatic update of process list ;;; Code: @@ -69,15 +66,13 @@ `(("user" ("ps" "-fu" ,(number-to-string (user-uid))) 2) ("all" ("ps" "-ef") 2)))) "Alist of commands to get list of processes. -Each element has the form (NAME COMMAND PID-COLUMN SORT-COLUMN). +Each element has the form (NAME COMMAND PID-COLUMN). NAME is a shorthand name to select the type of listing. COMMAND is a list (COMMAND-NAME ARG1 ARG2 ...), where COMMAND-NAME is the command to generate the listing (usually \"ps\"). ARG1, ARG2, ... are arguments passed to COMMAND-NAME to generate a particular listing. These arguments differ under various operating systems. -PID-COLUMN is the column number (starting from 1) of the process ID. -SORT-COLUMN is the column number used for sorting the process listing -\(must be a numeric field). If nil, the process listing is not sorted." +PID-COLUMN is the column number (starting from 1) of the process ID." :group 'proced :type '(repeat (group (string :tag "name") (cons (string :tag "command") @@ -90,11 +85,15 @@ SORT-COLUMN is the column number used for sorting the process listing Must be the car of an element of `proced-command-alist'." :group 'proced :type '(string :tag "name")) +(make-variable-buffer-local 'proced-command) -(defcustom proced-kill-program "kill" - "Name of kill command (usually `kill')." +(defcustom proced-signal-function 'signal-process + "Name of signal function. +It can be an elisp function (usually `signal-process') or a string specifying +the external command (usually \"kill\")." :group 'proced - :type '(string :tag "command")) + :type '(choice (function :tag "function") + (string :tag "command"))) (defcustom proced-signal-list '(("HUP (1. Hangup)") @@ -148,6 +147,7 @@ Important: the match ends just after the marker.") (defvar proced-procname-column nil "Proced command column. Initialized based on `proced-procname-column-regexp'.") +(make-variable-buffer-local 'proced-procname-column) (defvar proced-font-lock-keywords (list @@ -173,13 +173,16 @@ Initialized based on `proced-procname-column-regexp'.") (define-key km "d" 'proced-mark) ; Dired compatibility (define-key km "m" 'proced-mark) (define-key km "M" 'proced-mark-all) - (define-key km "g" 'revert-buffer) ; Dired compatibility - (define-key km "q" 'quit-window) (define-key km "u" 'proced-unmark) + (define-key km "\177" 'proced-unmark-backward) (define-key km "U" 'proced-unmark-all) + (define-key km "t" 'proced-toggle-marks) + (define-key km "h" 'proced-hide-processes) (define-key km "x" 'proced-send-signal) ; Dired compatibility (define-key km "k" 'proced-send-signal) ; kill processes (define-key km "l" 'proced-listing-type) + (define-key km "g" 'revert-buffer) ; Dired compatibility + (define-key km "q" 'quit-window) (define-key km [remap undo] 'proced-undo) (define-key km [remap advertised-undo] 'proced-undo) km) @@ -192,6 +195,9 @@ Initialized based on `proced-procname-column-regexp'.") ["Unmark" proced-unmark t] ["Mark All" proced-mark-all t] ["Unmark All" proced-unmark-all t] + ["Toggle Marks" proced-unmark-all t] + "--" + ["Hide Marked Processes" proced-hide-processes t] "--" ["Revert" revert-buffer t] ["Send signal" proced-send-signal t] @@ -201,8 +207,28 @@ Initialized based on `proced-procname-column-regexp'.") "(n)ext, (p)revious, (m)ark, (u)nmark, (k)ill, (q)uit (type ? for more help)" "Help string for proced.") +(defun proced-marker-regexp () + (concat "^" (regexp-quote (char-to-string proced-marker-char)))) + +(defun proced-success-message (action count) + (message "%s %s process%s" action count (if (= 1 count) "" "es"))) + +(defun proced-move-to-procname () + "Move to the beginning of the process name on the current line. +Return the position of the beginning of the process name, or nil if none found." + (beginning-of-line) + (if proced-procname-column + (forward-char proced-procname-column) + (forward-char 2))) + +(defsubst proced-skip-regexp () + "Regexp to skip in process listing." + (apply 'concat (make-list (1- (nth 2 (assoc proced-command + proced-command-alist))) + "\\s-+\\S-+"))) + (defun proced-mode (&optional arg) - "Mode for displaying UNIX processes and sending signals to them. + "Mode for displaying UNIX system processes and sending signals to them. Type \\[proced-mark-process] to mark a process for later commands. Type \\[proced-send-signal] to send signals to marked processes. @@ -240,15 +266,8 @@ information will be displayed but not selected. ;; Proced mode is suitable only for specially formatted data. (put 'proced-mode 'mode-class 'special) -(fset 'proced 'proced-mode) - -(defun proced-move-to-procname () - "Move to the beginning of the process name on the current line. -Return the position of the beginning of the process name, or nil if none found." - (beginning-of-line) - (if proced-procname-column - (forward-char proced-procname-column) - (forward-char 2))) +;;;###autoload +(defalias 'proced 'proced-mode) (defun proced-mark (&optional count) "Mark the current (or next COUNT) processes." @@ -260,20 +279,24 @@ Return the position of the beginning of the process name, or nil if none found." (interactive "p") (proced-do-mark nil count)) +(defun proced-unmark-backward (&optional count) + "Unmark the previous (or COUNT previous) processes." + (interactive "p") + (proced-do-mark nil (- (or count 1)))) + (defun proced-do-mark (mark &optional count) "Mark the current (or next ARG) processes using MARK." (or count (setq count 1)) - (let ((n (if (<= 0 count) 1 -1)) + (let ((backward (< count 0)) (line (line-number-at-pos)) buffer-read-only) ;; do nothing in the first line (unless (= line 1) - (setq count (1+ (cond ((<= 0 count) count) - ((< (abs count) line) (abs count)) - (t (1- line))))) + (setq count (1+ (if (<= 0 count) count + (min (- line 2) (abs count))))) (beginning-of-line) (while (not (or (zerop (setq count (1- count))) (eobp))) - (proced-insert-mark mark n)) + (proced-insert-mark mark backward)) (proced-move-to-procname)))) (defun proced-mark-all () @@ -288,18 +311,74 @@ Return the position of the beginning of the process name, or nil if none found." (defun proced-do-mark-all (mark) "Mark all processes using MARK." - (save-excursion - (let (buffer-read-only) + (let (buffer-read-only) + (save-excursion (goto-line 2) (while (not (eobp)) - (proced-insert-mark mark 1))))) + (proced-insert-mark mark))))) -(defun proced-insert-mark (mark n) - "If MARK is non-nil, insert `proced-marker-char', move N lines." - ;; Do we need other marks besides `proced-marker-char'? +(defun proced-toggle-marks () + "Toggle marks: marked processes become unmarked, and vice versa." + (interactive) + (let ((mark-re (proced-marker-regexp)) + buffer-read-only) + (save-excursion + (goto-line 2) + (while (not (eobp)) + (cond ((looking-at mark-re) + (proced-insert-mark nil)) + ((looking-at " ") + (proced-insert-mark t)) + (t + (forward-line 1))))))) + +(defun proced-insert-mark (mark &optional backward) + "If MARK is non-nil, insert `proced-marker-char'. +If BACKWARD is non-nil, move one line backwards before inserting the mark. +Otherwise move one line forward after inserting the mark." + (if backward (forward-line -1)) (insert (if mark proced-marker-char ?\s)) (delete-char 1) - (forward-line n)) + (unless backward (forward-line))) + +;; Mostly analog of `dired-do-kill-lines'. +;; However, for negative args the target lines of `dired-do-kill-lines' +;; include the current line, whereas `dired-mark' for negative args operates +;; on the preceding lines. Here we are consistent with `dired-mark'. +(defun proced-hide-processes (&optional arg quiet) + "Hide marked processes. +With prefix ARG, hide that many lines starting with the current line. +\(A negative argument hides backward.) +If QUIET is non-nil suppress status message. +Returns count of hidden lines." + (interactive "P") + (let ((mark-re (proced-marker-regexp)) + (count 0) + buffer-read-only) + (save-excursion + (if arg + ;; Hide ARG lines starting with the current line. + (let ((line (line-number-at-pos))) + ;; do nothing in the first line + (unless (= line 1) + (delete-region (line-beginning-position) + (save-excursion + (if (<= 0 arg) + (setq count (- arg (forward-line arg))) + (setq count (min (- line 2) (abs arg))) + (forward-line (- count))) + (point))))) + ;; Hide marked lines + (goto-line 2) + (while (and (not (eobp)) + (re-search-forward mark-re nil t)) + (delete-region (match-beginning 0) + (save-excursion (forward-line) (point))) + (setq count (1+ count))))) + (unless (zerop count) (proced-move-to-procname)) + (unless quiet + (proced-success-message "Hid" count)) + count)) (defun proced-listing-type (command) "Select `proced' listing type COMMAND from `proced-command-alist'." @@ -308,14 +387,9 @@ Return the position of the beginning of the process name, or nil if none found." (setq proced-command command) (proced-update)) -(defsubst proced-skip-regexp () - "Regexp to skip in process listing." - (apply 'concat (make-list (1- (nth 2 (assoc proced-command - proced-command-alist))) - "\\s-+\\S-+"))) - (defun proced-update (&optional quiet) "Update the `proced' process information. Preserves point and marks." + ;; This is the main function that generates and updates the process listing. (interactive) (or quiet (message "Updating process information...")) (let* ((command (cdr (assoc proced-command proced-command-alist))) @@ -342,16 +416,12 @@ Return the position of the beginning of the process name, or nil if none found." (goto-char (point-min)) (while (re-search-forward "[ \t\r]+$" nil t) (delete-region (match-beginning 0) (match-end 0))) + (set-buffer-modified-p nil) ;; set `proced-procname-column' (goto-char (point-min)) (and proced-procname-column-regexp (re-search-forward proced-procname-column-regexp nil t) (setq proced-procname-column (1- (match-beginning 0)))) - ;; sort fields - (goto-line 2) - (if (nth 2 command) - (sort-numeric-fields (nth 2 command) (point) (point-max))) - (set-buffer-modified-p nil) ;; restore process marks (if plist (save-excursion @@ -380,7 +450,8 @@ Return the position of the beginning of the process name, or nil if none found." "Analog of `revert-buffer'." (proced-update)) -;; I do not want to reinvent the wheel +;; I do not want to reinvent the wheel. Should we rename `dired-pop-to-buffer' +;; and move it to simple.el so that proced and ibuffer can easily use it, too? (autoload 'dired-pop-to-buffer "dired") (defun proced-send-signal (&optional signal) @@ -388,21 +459,23 @@ Return the position of the beginning of the process name, or nil if none found." SIGNAL may be a string (HUP, INT, TERM, etc.) or a number. If SIGNAL is nil display marked processes and query interactively for SIGNAL." (interactive) - (let ((regexp (concat "^\\*" (proced-skip-regexp) "\\s-+\\([0-9]+\\>\\).*$")) + (let ((regexp (concat (proced-marker-regexp) + (proced-skip-regexp) "\\s-+\\([0-9]+\\>\\).*$")) plist) ;; collect marked processes (save-excursion (goto-char (point-min)) (while (re-search-forward regexp nil t) (push (cons (match-string-no-properties 1) + ;; How much info should we collect here? Would it be + ;; better to collect only the PID (to avoid ambiguities) + ;; and the command name? (substring (match-string-no-properties 0) 2)) plist))) (if (not plist) (message "No processes marked") (unless signal ;; Display marked processes (code taken from `dired-mark-pop-up'). - ;; We include all process information to distinguish multiple - ;; instances of the same program. (let ((bufname " *Marked Processes*") (header (save-excursion (goto-char (+ 2 (point-min))) @@ -417,19 +490,48 @@ If SIGNAL is nil display marked processes and query interactively for SIGNAL." (save-window-excursion (dired-pop-to-buffer bufname) ; all we need (let* ((completion-ignore-case t) + (pnum (if (= 1 (length plist)) + "1 process" + (format "%d processes" (length plist)))) ;; The following is an ugly hack. Is there a better way ;; to help people like me to remember the signals and ;; their meanings? - (tmp (completing-read "Signal (default TERM): " + (tmp (completing-read (concat "Send signal [" pnum + "] (default TERM): ") proced-signal-list nil nil nil nil "TERM"))) (setq signal (if (string-match "^\\(\\S-+\\)\\s-" tmp) (match-string 1 tmp) tmp)))))) ;; send signal - (apply 'call-process proced-kill-program nil 0 nil - (concat "-" (if (numberp signal) - (number-to-string signal) signal)) - (mapcar 'car plist)) + (let ((count 0) + err-list) + (if (functionp proced-signal-function) + ;; use built-in `signal-process' + (let ((signal (if (stringp signal) + (if (string-match "\\`[0-9]+\\'" signal) + (string-to-number signal) + (make-symbol signal)) + signal))) ; number + (dolist (process plist) + (if (zerop (funcall + proced-signal-function + (string-to-number (car process)) signal)) + (push (cdr process) err-list) + (setq count (1+ count))))) + ;; use external system call + (let ((signal (concat "-" (if (numberp signal) + (number-to-string signal) signal)))) + (dolist (process plist) + (if (zerop (call-process + proced-signal-function nil 0 nil + signal (car process))) + (push (cdr process) err-list) + (setq count (1+ count)))))) + (if err-list + ;; FIXME: that's not enough to display the errors. + (message "%s: %s" signal err-list) + (proced-success-message "Sent signal to" count))) + ;; final clean-up (run-hooks 'proced-after-send-signal-hook))))) (defun proced-help ()