Function: proced-update
proced-update is an interactive and byte-compiled function defined in
proced.el.gz.
Signature
(proced-update &optional REVERT QUIET)
Documentation
Update the Proced process information. Preserves point and marks.
With prefix REVERT non-nil, revert listing.
Suppress status information if QUIET is nil.
After updating a displayed Proced buffer run the normal hook
proced-post-display-hook.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/proced.el.gz
(defun proced-update (&optional revert quiet)
"Update the Proced process information. Preserves point and marks.
With prefix REVERT non-nil, revert listing.
Suppress status information if QUIET is nil.
After updating a displayed Proced buffer run the normal hook
`proced-post-display-hook'."
;; This is the main function that generates and updates the process listing.
(interactive "P" proced-mode)
(setq revert (or revert (not proced-process-alist)))
(or quiet (message (if revert "Updating process information..."
"Updating process display...")))
(if revert ;; evaluate all processes
(setq proced-process-alist (proced-process-attributes)))
;; filtering and sorting
(setq proced-process-alist
(proced-sort (proced-filter proced-process-alist proced-filter)
proced-sort proced-descend))
;; display as process tree?
(setq proced-process-alist
(proced-tree proced-process-alist))
;; It is useless to keep undo information if we revert, filter, or
;; refine the listing so that `proced-process-alist' has changed.
;; We could keep the undo information if we only re-sort the buffer.
;; Would that be useful? Re-re-sorting is easy, too.
(if (consp buffer-undo-list)
(setq buffer-undo-list nil))
(let ((buffer-undo-list t)
;; If point is on a field, we try to return point to that field.
;; Otherwise we try to return to the same column
(old-pos (let ((pid (proced-pid-at-point))
(key (get-text-property (point) 'proced-key)))
(list pid key ; can both be nil
(if key
(if (get-text-property (1- (point)) 'proced-key)
(- (point) (previous-single-property-change
(point) 'proced-key))
0)
(current-column)))))
buffer-read-only mp-list)
;; remember marked processes (whatever the mark was)
(goto-char (point-min))
(while (re-search-forward "^\\(\\S-\\)" nil t)
(push (cons (save-match-data (proced-pid-at-point))
(match-string-no-properties 1)) mp-list))
;; generate listing
(erase-buffer)
(proced-format proced-process-alist proced-format)
(goto-char (point-min))
(while (not (eobp))
(insert " ")
(forward-line))
(setq proced-header-line (concat " " proced-header-line))
(if revert (set-buffer-modified-p nil))
;; set `goal-column'
(let ((grammar (assq proced-goal-attribute proced-grammar-alist)))
(setq goal-column ;; set to nil if no match
(if (and grammar
(not (zerop (buffer-size)))
(string-match (regexp-quote (nth 1 grammar))
proced-header-line))
(if (nth 3 grammar)
(match-beginning 0)
(match-end 0)))))
;; Restore process marks and buffer position (if possible).
;; Sometimes this puts point in the middle of the proced buffer
;; where it is not interesting. Is there a better / more flexible solution?
(goto-char (point-min))
(let (pid mark new-pos)
(if (or mp-list (car old-pos))
(while (not (eobp))
(setq pid (proced-pid-at-point))
(when (setq mark (assq pid mp-list))
(insert (cdr mark))
(delete-char 1)
(beginning-of-line))
(when (eq (car old-pos) pid)
(if (nth 1 old-pos)
(let ((limit (line-end-position)) pos)
(while (and (not new-pos)
(setq pos (next-property-change (point) nil limit)))
(goto-char pos)
(when (eq (nth 1 old-pos)
(get-text-property (point) 'proced-key))
(forward-char (min (nth 2 old-pos)
(- (next-property-change (point))
(point))))
(setq new-pos (point))))
(unless new-pos
;; we found the process, but the field of point
;; is not listed anymore
(setq new-pos (proced-move-to-goal-column))))
(setq new-pos (min (+ (line-beginning-position) (nth 2 old-pos))
(line-end-position)))))
(forward-line)))
(if new-pos
(goto-char new-pos)
(goto-char (point-min))
(proced-move-to-goal-column)))
;; update mode line
;; Does the long `mode-name' clutter the mode line? It would be nice
;; to have some other location for displaying the values of the various
;; flags that affect the behavior of proced (flags one might want
;; to change on the fly). Where??
(setq mode-name
(concat "Proced"
(if proced-filter
(concat ": " (symbol-name proced-filter))
"")
(if proced-sort
(let* ((key (if (consp proced-sort) (car proced-sort)
proced-sort))
(grammar (assq key proced-grammar-alist)))
(concat " by " (if proced-descend "-" "+")
(nth 1 grammar)))
"")))
(force-mode-line-update)
;; run `proced-post-display-hook' only for a displayed buffer.
(if (get-buffer-window) (run-hooks 'proced-post-display-hook))
;; done
(or quiet (input-pending-p)
(message (if revert "Updating process information...done."
"Updating process display...done.")))))