我正在尋找/ usr/bin/uptime輸出顯示在emacs狀態欄上? 我在centos上使用GNU Emacs 23.1.1。如何在emacs狀態欄上顯示正常運行時間?我正在尋找/ usr/bin/uptime輸出顯示在狀態欄
謝謝
我正在尋找/ usr/bin/uptime輸出顯示在emacs狀態欄上? 我在centos上使用GNU Emacs 23.1.1。如何在emacs狀態欄上顯示正常運行時間?我正在尋找/ usr/bin/uptime輸出顯示在狀態欄
謝謝
@louxius建議值得關注。至於具體實施,這裏是從my .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)))
...
我想顯示不同的東西在那裏,很明顯,但是這應該是你一個體面的起點。
非常感謝。您的.emacs幫助我瞭解如何調用外部命令。 –
我的系統上沒有uptime
,所以我無法爲您測試此功能。但它應該給你一個想法。似乎在我的系統上工作,用ps
代替uptime
。
也許別人會提供更簡單或更乾淨的解決方案。你也可以看看call-process
或start-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))))
"-%-"))
非常感謝。它幫助了我 –
我定義了一個小的模式,並使用'用空閒-timer'更新模式行(那是狀態欄,對不對?) – 2013-08-20 13:57:25
哎呀,這在我以前的評論中丟失了:http://www.gnu.org/software/emacs/manual/html_node/elisp/Mode-Line-Basics.html。 – 2013-08-20 14:07:36
爲什麼'M-!'''正常運行時間'不夠? –