1

Day One是OSX上非常精美的一款日记软件, 我已使用很久了. 它同时还有iOS的客户端, 包括iPhone和iPad.

dayone

dayone

今天发现One Day还有Command Line工具,翻了一下文档,发现这个CLI功能非常全面.既然有功能全面的CLI工具,那么必须就可以在Emacs里使用了!

  • Day One Command Line Examples
$ ./dayone new
Waits for input from stdin then creates a new entry in the default journal

$ echo "an entry from yesterday" | ./dayone -d="yesterday" new
Creates a new entry using yesterday’s date with the specified text

$ ./dayone -d="25/03/2011 5:30PM" -s=true new < ~/Desktop/note.txt
Creates a starred entry using the contents of note.txt

$ echo "an entry in my other journal" | ./dayone -j=~/Documents/WorkJournal.dayone new
Creates an entry in a journal other than the default

下面是在Emacs里通过One Day CLI来操作One Day.

;; dayone.el

;; venmos .emacs.d/elisp/
;; http://blog.venmos.com
;; me[at]venmos.com

;; 基于 One Day 命令行工具创建的 Elisp 包, 可以在 Emacs 里创建 One Day 日记.
;; dayone-cli https://dayone.zendesk.com/hc/en-us/articles/200258954-Day-One-Tools

(defvar path-to-dayone "/usr/local/bin/dayone"
  "Executable path to DayOne CLI")

(defun dayone-save-new-entry ()
  "Save buffer as a new DayOne entry"
  (interactive)
  (if (executable-find path-to-dayone)
      (call-process-region
       1 (point-max) path-to-dayone nil nil nil "new")))

(defvar dayone-buffer "*dayone*"
  "The name of the dayone buffer.")

(defvar dayone-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "\C-c\C-c" 'dayone-save-and-kill-buffer)
    (define-key map "\C-c\C-k" 'dayone-destroy-buffer)
    map)
  "Keymap used in DayOne mode.")

(defun dayone-create-new-entry ()
  "Create *DayOne* buffer in new window."
  (interactive)
  (switch-to-buffer (get-buffer-create dayone-buffer))
  (use-local-map dayone-mode-map)
  (setq major-mode 'dayone-mode mode-name "DayOne"))

(defun dayone-save-and-kill-buffer ()
  (interactive)
  (dayone-save-new-entry)
  (dayone-destroy-buffer))

(defun dayone-destroy-buffer ()
  "Destroy the current *DayOne* buffer."
  (interactive)
  (if (equal dayone-buffer (buffer-name))
      (kill-buffer (current-buffer))))
;;; init-dayone.el ends here
  • dayone-create-new-entry
    新建一条日志
  • dayone-save-and-kill-buffer
    保存日志并关闭Buffer
  • dayone-destroy-buffer
    删除已输入的日志并关闭Buffer

venmos
462 声望15 粉丝

Maccon, Emacscon, Lolicon, ACG. False geek, Looks like a quiet guy. Love open source, Loves photography and outdoor sports. Favorite programming language is Ruby and Lisp.


引用和评论

0 条评论