在Emacs中显示天气

wttr.in is a console-oriented weather forecast service that supports various information representation methods like terminal-oriented ANSI-sequences for console HTTP clients (curl, httpie, or wget), HTML for web browsers, or PNG for graphical viewers.

在Emacs中,可以通过调用命令 curl -s "wttr.in/WuHan?format=4&M" 来获取单行输出的天气信息,为避免阻塞其他任务,需要采用异步调用的方式,通过定时器周期去更新天气。

(defvar +echo-bar--weather-string "")
(defvar +echo-bar--weather-url "wttr.in/WuHan?format=4&M")
(defun +echo-bar--weather-update ()
  (let* ((output-buffer (generate-new-buffer "*weather-output*"))
         ;; Start the process, directing output to `output-buffer`
         (proc (start-process "weather-proc" output-buffer "curl" "-s" +echo-bar--weather-url)))
    ;; Process filter: append output to the process's associated buffer
    ;; (set-process-filter
    ;;  proc
    ;;  (lambda (p string)
    ;;    (with-current-buffer (process-buffer p)
    ;;      (insert string))))
    ;; Process sentinel: called when the process changes state (e.g., finished)
    (set-process-sentinel
     proc
     (lambda (p event)
       (let ((buffer (process-buffer p)))
         (cond
          ((and (memq (process-status p) '(exit signal))
                (/= (process-exit-status p) 0))
           (message "Weather update error")
           (when (buffer-live-p buffer)
             (kill-buffer buffer)))
          ((cl-search "finished" event)
           (setq +echo-bar--weather-string
                 (replace-regexp-in-string "[ \t\n\r]+" "" (with-current-buffer buffer (buffer-string))))
           (when (buffer-live-p buffer)
             (kill-buffer buffer)))))))))
(run-at-time nil 1800 #'+echo-bar--weather-update)

成功获取的天气信息 WuHan:🌫🌡️+4°C🌬️↗1.7m/s ,可以显示到 mode-line 或者 echo-bar 中。

Related

雾凇拼音简繁转换

朙月拼音和双拼默认使用的是繁体字库,输入方案中转换简体功能,是通过内置OpenCC进行转换的,词典中保存的都是繁体。

安装雾凇拼音词库

雾凇拼音提供了一套开箱即用的完整配置,包含输入方案(全拼、常见双拼)、长期维护的开源词库及各项扩展功能。

在WSL中使用emacs-rime

在WSL中使用Emacs时,无法直接使用Windows安装的RIME输入法,当前比较好的方案是在WSL中安装librime,在Emacs中使用emacs-rime作为前端,使用体验比较贴近原生RIME输入法。