comparison lisp/proced.el @ 98172:87d64c3d48ac

(proced-mark-face, proced-marked-face) (proced-sort-header-face): Removed. (proced-font-lock-keywords): Simplified. (proced-format): Use face proced-sort-header. (proced-format-interactive, proced-sort-interactive) (proced-filter-interactive): Only call proced-update if the scheme has changed. (proced-sort-header): Use posn-actual-col-row.
author Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
date Sun, 14 Sep 2008 16:43:56 +0000
parents d5c5ea23d8ea
children 538f59dc1be8
comparison
equal deleted inserted replaced
98171:b9386bd24a89 98172:87d64c3d48ac
269 "Sort scheme for listing (internal format).") 269 "Sort scheme for listing (internal format).")
270 270
271 (defvar proced-marker-char ?* ; the answer is 42 271 (defvar proced-marker-char ?* ; the answer is 42
272 "In proced, the current mark character.") 272 "In proced, the current mark character.")
273 273
274 ;; face and font-lock code taken from dired 274 ;; Faces and font-lock code taken from dired,
275 ;; but face variables are deprecated for new code.
275 (defgroup proced-faces nil 276 (defgroup proced-faces nil
276 "Faces used by Proced." 277 "Faces used by Proced."
277 :group 'proced 278 :group 'proced
278 :group 'faces) 279 :group 'faces)
279 280
280 (defface proced-mark 281 (defface proced-mark
281 '((t (:inherit font-lock-constant-face))) 282 '((t (:inherit font-lock-constant-face)))
282 "Face used for proced marks." 283 "Face used for proced marks."
283 :group 'proced-faces) 284 :group 'proced-faces)
284 (defvar proced-mark-face 'proced-mark
285 "Face name used for proced marks.")
286 285
287 (defface proced-marked 286 (defface proced-marked
288 '((t (:inherit font-lock-warning-face))) 287 '((t (:inherit font-lock-warning-face)))
289 "Face used for marked processes." 288 "Face used for marked processes."
290 :group 'proced-faces) 289 :group 'proced-faces)
291 (defvar proced-marked-face 'proced-marked
292 "Face name used for marked processes.")
293 290
294 (defface proced-sort-header 291 (defface proced-sort-header
295 '((t (:inherit font-lock-keyword-face))) 292 '((t (:inherit font-lock-keyword-face)))
296 "Face used for header of attribute used for sorting." 293 "Face used for header of attribute used for sorting."
297 :group 'proced-faces) 294 :group 'proced-faces)
298 (defvar proced-sort-header-face 'proced-sort-header
299 "Face name used for header of attribute used for sorting.")
300 295
301 (defvar proced-re-mark "^[^ \n]" 296 (defvar proced-re-mark "^[^ \n]"
302 "Regexp matching a marked line. 297 "Regexp matching a marked line.
303 Important: the match ends just after the marker.") 298 Important: the match ends just after the marker.")
304 299
326 (defconst proced-field-help-echo 321 (defconst proced-field-help-echo
327 "mouse-2, RET: refine by attribute %s %s" 322 "mouse-2, RET: refine by attribute %s %s"
328 "Help string shown when mouse is over a refinable field.") 323 "Help string shown when mouse is over a refinable field.")
329 324
330 (defvar proced-font-lock-keywords 325 (defvar proced-font-lock-keywords
331 (list 326 `(;; (Any) proced marks.
332 ;; 327 (,proced-re-mark . 'proced-mark)
333 ;; Proced marks. 328 ;; Processes marked with `proced-marker-char'
334 (list proced-re-mark '(0 proced-mark-face)) 329 ;; Should we make sure that only certain attributes are font-locked?
335 ;; 330 (,(concat "^[" (char-to-string proced-marker-char) "]")
336 ;; Marked files. 331 ".+" (proced-move-to-goal-column) nil (0 'proced-marked))))
337 (list (concat "^[" (char-to-string proced-marker-char) "]")
338 '(".+" (proced-move-to-goal-column) nil (0 proced-marked-face)))))
339 332
340 (defvar proced-mode-map 333 (defvar proced-mode-map
341 (let ((km (make-sparse-keymap))) 334 (let ((km (make-sparse-keymap)))
342 ;; moving 335 ;; moving
343 (define-key km " " 'proced-next-line) 336 (define-key km " " 'proced-next-line)
784 Set variable `proced-filter' to SCHEME. Revert listing." 777 Set variable `proced-filter' to SCHEME. Revert listing."
785 (interactive 778 (interactive
786 (let ((scheme (completing-read "Filter: " 779 (let ((scheme (completing-read "Filter: "
787 proced-filter-alist nil t))) 780 proced-filter-alist nil t)))
788 (list (if (string= "" scheme) nil (intern scheme))))) 781 (list (if (string= "" scheme) nil (intern scheme)))))
789 (setq proced-filter scheme) 782 ;; only update if necessary
790 (proced-update t)) 783 (unless (eq proced-filter scheme)
784 (setq proced-filter scheme)
785 (proced-update t)))
791 786
792 (defun proced-process-tree (process-alist) 787 (defun proced-process-tree (process-alist)
793 "Return process tree for PROCESS-ALIST. 788 "Return process tree for PROCESS-ALIST.
794 The process tree is an alist with elements (PPID PID1 PID2 ...). 789 The process tree is an alist with elements (PPID PID1 PID2 ...).
795 PPID is a parent PID. PID1, PID2, ... are the child processes of PPID. 790 PPID is a parent PID. PID1, PID2, ... are the child processes of PPID.
974 (interactive 969 (interactive
975 (let ((scheme (completing-read "Sort attribute: " 970 (let ((scheme (completing-read "Sort attribute: "
976 proced-grammar-alist nil t))) 971 proced-grammar-alist nil t)))
977 (list (if (string= "" scheme) nil (intern scheme)) 972 (list (if (string= "" scheme) nil (intern scheme))
978 current-prefix-arg))) 973 current-prefix-arg)))
979 (setq proced-sort scheme) 974 ;; only update if necessary
980 (proced-update revert)) 975 (when (or (not (eq proced-sort scheme)) revert)
976 (setq proced-sort scheme)
977 (proced-update revert)))
981 978
982 (defun proced-sort-pcpu (&optional revert) 979 (defun proced-sort-pcpu (&optional revert)
983 "Sort Proced buffer by percentage CPU time (%CPU)." 980 "Sort Proced buffer by percentage CPU time (%CPU)."
984 (interactive "P") 981 (interactive "P")
985 (proced-sort-interactive 'pcpu revert)) 982 (proced-sort-interactive 'pcpu revert))
1011 1008
1012 (defun proced-sort-header (event &optional revert) 1009 (defun proced-sort-header (event &optional revert)
1013 "Sort Proced listing based on an attribute. 1010 "Sort Proced listing based on an attribute.
1014 EVENT is a mouse event with starting position in the header line. 1011 EVENT is a mouse event with starting position in the header line.
1015 It is converted in the corresponding attribute key. 1012 It is converted in the corresponding attribute key.
1016 This updates the variable `proced-sort'." 1013 This command updates the variable `proced-sort'."
1017 (interactive "e\nP") 1014 (interactive "e\nP")
1018 (let ((start (event-start event)) 1015 (let ((start (event-start event))
1019 col key) 1016 col key)
1020 (save-selected-window 1017 (save-selected-window
1021 (select-window (posn-window start)) 1018 (select-window (posn-window start))
1022 (setq col (+ (1- (car (posn-col-row start))) 1019 (setq col (+ (1- (car (posn-actual-col-row start)))
1023 (window-hscroll))) 1020 (window-hscroll)))
1024 (when (and (<= 0 col) (< col (length proced-header-line))) 1021 (when (and (<= 0 col) (< col (length proced-header-line)))
1025 (setq key (get-text-property col 'proced-key proced-header-line)) 1022 (setq key (get-text-property col 'proced-key proced-header-line))
1026 (if key 1023 (if key
1027 (proced-sort-interactive key revert) 1024 (proced-sort-interactive key revert)
1105 (nth 7 grammar) "")))) 1102 (nth 7 grammar) ""))))
1106 value) 1103 value)
1107 1104
1108 ;; highlight the header of the sort column 1105 ;; highlight the header of the sort column
1109 (if (eq key proced-sort) 1106 (if (eq key proced-sort)
1110 (setq hprops (append `(face ,proced-sort-header-face) hprops))) 1107 (setq hprops (append '(face proced-sort-header) hprops)))
1111 (goto-char (point-min)) 1108 (goto-char (point-min))
1112 (cond ( ;; fixed width of output field 1109 (cond ( ;; fixed width of output field
1113 (numberp (nth 3 grammar)) 1110 (numberp (nth 3 grammar))
1114 (dolist (process process-alist) 1111 (dolist (process process-alist)
1115 (end-of-line) 1112 (end-of-line)
1177 (interactive 1174 (interactive
1178 (let ((scheme (completing-read "Format: " 1175 (let ((scheme (completing-read "Format: "
1179 proced-format-alist nil t))) 1176 proced-format-alist nil t)))
1180 (list (if (string= "" scheme) nil (intern scheme)) 1177 (list (if (string= "" scheme) nil (intern scheme))
1181 current-prefix-arg))) 1178 current-prefix-arg)))
1182 (setq proced-format scheme) 1179 ;; only update if necessary
1183 (proced-update revert)) 1180 (when (or (not (eq proced-format scheme)) revert)
1181 (setq proced-format scheme)
1182 (proced-update revert)))
1184 1183
1185 ;; generate listing 1184 ;; generate listing
1186 1185
1187 (defun proced-process-attributes () 1186 (defun proced-process-attributes ()
1188 "Return alist of attributes for each system process. 1187 "Return alist of attributes for each system process.