Skip to content

Instantly share code, notes, and snippets.

@sanryuu
Created December 11, 2013 16:35
Show Gist options
  • Save sanryuu/7913754 to your computer and use it in GitHub Desktop.
Save sanryuu/7913754 to your computer and use it in GitHub Desktop.
ログの最新版のみバッファに取得するメソッド
(setq file-size (make-hash-table :test #'equal))
(defun re-load-log (file-name)
(interactive)
(let (point-last-read regenesis)
(setq point-last-read (gethash file-name file-size))
(with-temp-buffer
(insert-file-contents file-name)
(when (> point-last-read (point-max))
(setq point-last-read (point-min)))
(when (not point-last-read)
(setq point-last-read (point-min)))
(setq regenesis
(buffer-substring-no-properties point-last-read (point-max)))
(puthash file-name (point-max) file-size)
)
(switch-to-buffer
(get-buffer-create
(format "*regenesis %s*" file-name)))
(cond ((< 0 (length regenesis))
(delete-region (point-min) (point-max))
(insert (decode-coding-string
(encode-coding-string regenesis 'utf-8) 'utf-8))
(message "reload done."))
(t
(message "No changes.")))))
(global-set-key "\C-cl" '(lambda () (interactive) (re-load-log "path/to/log")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment