4

我正在寻找要在 emacs 状态栏上显示的 /usr/bin/uptime 输出?我在 centos 上使用 GNU Emacs 23.1.1。

谢谢

4

3 回答 3

2

@louxius 的建议值得关注。至于具体实现,这是我.emacs的一个片段:

...
;; custom modeline
(setq-default 
 mode-line-format
 (list " " 'mode-line-modified          ;; the "**" at the beginning
       "--" 'mode-line-buffer-identification    ;; buffer file name
       "--" 'mode-line-modes            ;; major and minor modes in effect
       'mode-line-position          ;; line, column, file %
       "--" '(:eval (battery-status))
       "--" '(:eval (temperature))
       "--" '(:eval (format-time-string "%I:%M" (current-time)))
       "-%-"))                  ;; dashes sufficient to fill rest of modeline.

(defun battery-status ()
  "Outputs the battery percentage from acpi."
  (replace-regexp-in-string 
   ".*?\\([0-9]+\\)%.*" " Battery: \\1%% " 
   (substring (shell-command-to-string "acpi") 0 -1)))

(defun temperature ()
  (replace-regexp-in-string
   ".*? \\([0-9\.]+\\) .*" "Temp: \\1°C "
   (substring (shell-command-to-string "acpi -t") 0 -1)))
...

显然,我希望在那里显示不同的东西,但这对你来说应该是一个不错的起点。

于 2013-08-20T14:39:10.750 回答
2

我的系统上没有uptime,所以我不能为你测试这个。但它应该给你一个想法。似乎可以在我的系统上使用ps替换为uptime.

也许其他人会提供更简单或更清洁的解决方案。您也可以查看call-processstart-process代替shell-command-to-string---start-process是异步的。您可能还想考虑使用空闲计时器 --- 此处的代码会大大降低 Emacs 的速度,因为它会在uptime每次更新模式行时调用。

(setq-default 
 mode-line-format
 (list " " 'mode-line-modified
       "--" 'mode-line-buffer-identification
       "--" 'mode-line-modes
       'mode-line-position
       "--" '(:eval (shell-command-to-string "uptime"))
       "-%-"))

这是另一种方法,它似乎并没有明显减慢速度:

(defun bar ()
  (with-current-buffer (get-buffer-create "foo")
    (erase-buffer)
    (start-process "ps-proc" "foo" "uptime")))

(setq foo (run-with-idle-timer 30 'REPEAT 'bar))

(setq-default 
 mode-line-format
 (list " " 'mode-line-modified
       "--" 'mode-line-buffer-identification
       "--" 'mode-line-modes
       'mode-line-position
       "--" '(:eval (with-current-buffer (get-buffer-create "foo")
                      (buffer-substring (point-min) (point-max))))
       "-%-"))
于 2013-08-20T15:55:01.597 回答
1

查找功能emacs-uptime。并查看此链接以自定义模式行。

于 2013-08-20T13:57:40.203 回答