top  Index  Search  Changes  RSS  Login

IgnoreMinorChange

Wikiなんかにある「タイムスタンプを更新しない」的なものってできないでしょうか? - 2ch2:576

…ごめんなさい. すぐにはしんどそうです. すごく必要でしょうか?

  • ファイルの更新時刻をいじる → 互換性が?
  • 更新時刻を自前で記録 → めんどそう

たわむれにでっちあげてはみたけど…

;; M-x my-howm-save-as-minor で, 「マイナーチェンジとして保存」.
;; すると, howm-list-recent に現れなくなる.
;; 普通に保存しなおせば, また現れるようになる.
;; (howm-test050212 で動作確認)
;; 
;; 【警告】 ひどい実装. こけても泣かない約束で.
;; ・ファイル名を *-m.howm に変えることで印をつける, ひどいとんち
;; ・そんなあぶなっかしいことをするのに, ほとんどテストしてない
;; ・今後まじめにサポートするつもりもない

(defvar my-howm-minor-ending "-m.howm")
(defvar my-howm-major-ending ".howm")
(defvar my-howm-major-command '(howm-list-recent)
  "List of commands which ignore minor changes.
Command means the value of `howm-command' here.")

(defun my-howm-ending-regexp (ending)
  (concat (regexp-quote ending) "$"))
(defun my-howm-minor-regexp ()
  (my-howm-ending-regexp my-howm-minor-ending))
(defun my-howm-major-regexp ()
  (my-howm-ending-regexp my-howm-major-ending))

(defun my-howm-minor-p (file)
  (string-match (my-howm-minor-regexp) file))
(defun my-howm-set-minor-p (new-val)
  (let ((file (buffer-file-name)))
    (if (null file)
        (error "No file is visited.")
      (let* ((old-minor-p (my-howm-minor-p file))
             need-change old-ending new-ending msg)
        (if new-val
            (setq need-change (not old-minor-p)
                  old-ending my-howm-major-ending
                  new-ending my-howm-minor-ending
                  msg "minor")
          (setq need-change old-minor-p
                old-ending my-howm-minor-ending
                new-ending my-howm-major-ending
                msg "major"))
        (when need-change
          (let* ((old-reg (my-howm-ending-regexp old-ending))
                 (newname (replace-regexp-in-string old-reg new-ending file)))
            (rename-file file newname)
            (set-visited-file-name newname 'no-query 'along-with-file)
            (message "Wrote %s as %s change" (buffer-file-name) msg)))))))

(defadvice howm-exclude-p (around ignore-minor (filename) activate)
  (if (and (member (howm-command) my-howm-major-command)
           (my-howm-minor-p filename))
      (setq ad-return-value t)
    ad-do-it))

(defvar *my-howm-minor-flag* nil "For internal use")

(defadvice howm-after-save (around set-minor-flag activate)
  ad-do-it
  (when howm-mode
    (my-howm-set-minor-p *my-howm-minor-flag*)))

(defun my-howm-save-as-minor ()
  (interactive)
  (let ((*my-howm-minor-flag* t))
    (call-interactively 'save-buffer)))

もいっちょ, こっちは単純な解 (howm 関係なし). 外部プロセスなしでできんのかね?

;; M-x my-save-buffer-keep-timestamp
;;   → ファイルを保存しつつも, タイムスタンプは元のまま
;; 
;; ただし, 関数 my-set-timestamp は各自の環境にあわせて自作してください :p

(defvar my-set-timestamp-touch "/bin/touch")  ;; need GNU touch?
(defun my-set-timestamp (file ti)
  (call-process my-set-timestamp-touch nil nil nil
                "-t" (format-time-string "%Y%m%d%H%M.%S" ti)
                (expand-file-name file)))

(defun my-save-buffer-keep-timestamp ()
  (interactive)
  (let* ((file (buffer-file-name))
         (mtime (nth 5 (file-attributes file))))
    (prog1
        (call-interactively 'save-buffer)
      (when file
        (my-set-timestamp file mtime)
        (set-visited-file-modtime)))))

;; 更新順でなく作成順に並べる
(setq howm-list-normalizer 'howm-view-sort-by-reverse-date)
(Please LogIn to post comments.)

Last modified:2008/03/09 14:11:39
Keyword(s):
References:[併用ツール]