Blog

Emacs で一人 Twitter

Day One で一人 Twitter しよう、みたいなエントリをたまにみるんだけど、正直 Day One の iPhone アプリはつかいづらいし、なんか day one の mac アプリもなんかいちいちひらくのが面倒でつかってなかった。

そこで、われわれのような Emacs 厨は常時 Emacs を開き、その中で一生の大部分をすごしているので、emacs でひとり twitter っぽくしようと考えた。

change-log-mode をちょっと改造して、ささっと設定。いいかんじである。

見た目は ↓ のようなかんじ。

--- /tmp/zshdRLJOW	2012-07-24 11:50:43.060566000 +0900
+++ .emacs.d/elisp/hacked-add-log.el	2012-07-24 11:43:53.712566000 +0900
@@ -442,16 +442,16 @@
 	  (goto-char (point-min)))
 	(let (current-defun)
 	  (while (and (not last) (re-search-forward regexp nil t))
-	      ;; Verify that `add-log-current-defun' invoked at the end
-	      ;; of the match returns TAG.  This heuristic works well
-	      ;; whenever the name of the defun occurs within the first
-	      ;; line of the defun.
-	      (setq current-defun (add-log-current-defun))
-	      (when (and current-defun (string-equal current-defun tag))
-		;; Record this as last match.
-		(setq last (line-beginning-position))
-		;; Record this as first match when there's none.
-		(unless first (setq first last)))))))
+	    ;; Verify that `add-log-current-defun' invoked at the end
+	    ;; of the match returns TAG.  This heuristic works well
+	    ;; whenever the name of the defun occurs within the first
+	    ;; line of the defun.
+	    (setq current-defun (add-log-current-defun))
+	    (when (and current-defun (string-equal current-defun tag))
+	      ;; Record this as last match.
+	      (setq last (line-beginning-position))
+	      ;; Record this as first match when there's none.
+	      (unless first (setq first last)))))))
     (if (or last first)
 	(with-selected-window
 	    (setq change-log-find-window (or window (display-buffer buffer)))
@@ -703,11 +703,11 @@
   ;; in order to respect buffer-local settings of change-log-default-name, etc.
   (with-current-buffer (let ((buff (if (derived-mode-p 'diff-mode)
 				       (car (ignore-errors
-					     (diff-find-source-location))))))
+					      (diff-find-source-location))))))
 			 (if (buffer-live-p buff) buff
 			   (current-buffer)))
-      ;; If user specified a file name or if this buffer knows which one to use,
-      ;; just use that.
+    ;; If user specified a file name or if this buffer knows which one to use,
+    ;; just use that.
     (or file-name
 	(setq file-name (and change-log-default-name
 			     (file-name-directory change-log-default-name)
@@ -767,7 +767,7 @@
 (defun add-change-log-entry (&optional whoami file-name other-window new-entry
 				       put-new-entry-on-new-line)
   "Find change log file, and add an entry for today and an item for this file.
-Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
+Optional arg WHOAMI (interative prefix) non-nil means prompt for user
 name and email (stored in `add-log-full-name' and `add-log-mailing-address').
 
 Second arg FILE-NAME is file name of the change log.
@@ -835,9 +835,9 @@
 
       ;; If file starts with a copyright and permission notice, skip them.
       ;; Assume they end at first blank line.
-      (when (looking-at "Copyright")
-        (search-forward "\n\n")
-        (skip-chars-forward "\n"))
+      ;; (when (looking-at "Copyright")
+      ;; (search-forward "\n\n")
+      ;;(skip-chars-forward "\n"))
 
       ;; Advance into first entry if it is usable; else make new one.
       (let ((new-entries
@@ -851,8 +851,7 @@
                                     (funcall add-log-time-format))
                                 (set-time-zone-rule tz)))
                           (funcall add-log-time-format))
-                        "  " full-name
-                        "  <" addr ">"))
+                        ))
                      (if (consp mailing-address)
                          mailing-address
                        (list mailing-address)))))
@@ -890,7 +889,9 @@
                      (concat (regexp-quote (concat "* " item))
                              ;; Don't accept `foo.bar' when
                              ;; looking for `foo':
-                             "\\(\\s \\|[(),:]\\)")
+                             "DO NOT MATCH ME\\(\\s \\|[(),:]\\)")
+		          ;; "\\(\\s \\|[(),:]\\)")
+		     ;; ↑ (\d\d:\d\d) の部分を無視しないように変更
                      bound t)))
              ;; Add to the existing item for the same file.
              (re-search-forward "^\\s *$\\|^\\s \\*")
@@ -914,11 +915,13 @@
              (forward-line -2)
              (indent-to left-margin)
              (insert "* ")
+	     (insert (format-time-string "(%H:%M) "))
              (if item (insert item)))))
     ;; Now insert the function name, if we have one.
     ;; Point is at the item for this file,
     ;; either at the end of the line or at the first blank line.
-    (if (not defun)
+    (if t
+	;;    (if (not defun)
 	;; No function name, so put in a colon unless we have just a star.
 	(unless (save-excursion
 		  (beginning-of-line 1)
@@ -1227,7 +1230,7 @@
   (goto-char (match-end 0)))
 
 (defun change-log-get-method-definition ()
-"For Objective C, return the method name if we are in a method."
+  "For Objective C, return the method name if we are in a method."
   (let ((change-log-get-method-definition-md "["))
     (save-excursion
       (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)

あとはなんか適当に設定する。

(setq add-log-keep-changes-together t)

(setq add-log-time-format
      (function (lambda ()
		  (let ((system-time-locale "C"))
		    (concat (add-log-iso8601-time-string)
			    " " "(" (format-time-string "%a") ")")))
		))
(setq add-log-file-name-function (function (lambda (fname) "")))
;; (function (lambda (fname) (format-time-string "(%H:%M) "))))
(add-hook 'change-log-mode-hook
      (function (lambda ()
		  (make-local-variable 'tab-width)
		  (make-local-variable 'left-margin)
		  (setq tab-width 4)
		  (setq left-margin 4)
		  )))

なお、Dropbox で ~/Dropbox/howm/diaries/iMac.txt のような感じでファイルを保存しているのでバックアップも万全である。