TAB と共生するために、その1。Emacs で TAB、全角スペース、行末スペースに色をつけたり、下線を引いたりする。
便利。全米が泣いた。ネタ元。
Meadow/Emacs memoには大量の Tips がある。メモ。
色を light gray に変えた。
(defface my-face-r-1 '((t (:background "light gray"))) nil)
(defadvice font-lock-mode (before my-font-lock-mode ())
(defvar my-face-r-1 'my-face-r-1)
(font-lock-add-keywords
major-mode
'(("\t" 0 my-face-r-1 append)
(" " 0 my-face-r-1 append)
("[ \t]+$" 0 my-face-r-1 append)
;;("[\r]*\n" 0 my-face-r-1 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
最初にソースにドキュメントを埋め込もうと言い出した奴は誰なんだろう。ソースが見にくくなるのに。
RDoc も量が多いとソースが非常に読みにくい。というわけで、コメントを Emacs の hideshow.el を使ってコメントを隠す裏技。ネタ元。
.emacs.el に以下を追加。
(add-hook 'ruby-mode-hook
'(lambda()
(hs-minor-mode 1)))
(let ((ruby-mode-hs-info
'( ruby-mode
"class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do"
"end"
"#"
ruby-move-to-block
nil)))
(if (not (member ruby-mode-hs-info hs-special-modes-alist))
(setq hs-special-modes-alist
(cons ruby-mode-hs-info hs-special-modes-alist))))
意外なことに hideshow.el には hs-hide-all-comments という関数がない。だから作ってみた。
(defun hs-hide-all-comments ()
(interactive)
(hs-life-goes-on
(message "Hiding all comments ...")
(save-excursion
(hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness
(goto-char (point-min))
(let (c-reg (count 0))
(while (re-search-forward hs-c-start-regexp (point-max) t)
(if (match-beginning 1) ;; we have found a block beginning
(progn
(goto-char (match-beginning 1))
(hs-hide-block-at-point t)
(message "Hiding ... %d" (setq count (1+ count))))
;;found a comment
(setq c-reg (hs-inside-comment-p))
(if (and c-reg (car c-reg))
(if (> (count-lines (car c-reg) (nth 1 c-reg))
(if hs-show-hidden-short-form 1 2))
(progn
(hs-hide-block-at-point t c-reg)
(message "Hiding ... %d" (setq count (1+ count))))
(goto-char (nth 1 c-reg))))))))
(hs-safety-is-job-n))
(beginning-of-line)
(message "Hiding all comments ... done")
(run-hooks 'hs-hide-hook))
.emacs.el に書いておけば、M-x hs-hide-all-comments でコメントが全て隠れる。たぶん便利。
最近のコメント