[emacs][anything] anything-c-source-mark-ring の修正と機能追加

global-mark-ring バージョンの新規作成と、何故か init が指定してあったので削除。
候補の文字列を取得する際に、オリジナルanything-c-source-mark-ringで使っていた thing-at-point を使用するように変更。
global-mark-ringの実装は全く自信なし。。

2008/12/8 手直しとanything-persistent-highlight-pointの説明追加
2009/1/8 current-line を line-number-at-pos に変更。

current-line は moccur-edit.el の関数だった(気がつかなかったorz)。
EmacsWikiにも投稿したので、そっちの方が最新。ただし anything-c-persistent-highlight-point は削除してある。

(defvar anything-c-source-mark-ring
  '((name . "mark-ring")
    (candidates . anything-c-source-mark-ring-candidates)
    (action . (("Goto line" . (lambda (candidate)
                                (goto-line (string-to-number candidate))))))
    (persistent-action . (lambda (candidate)
                           (switch-to-buffer anything-current-buffer)
                           (goto-line (string-to-number candidate))
                           (set-window-start (get-buffer-window anything-current-buffer) (point))
                            
                           (anything-persistent-highlight-point
                            (line-beginning-position)
                            (line-end-position)
                            anything-current-buffer)
                           ))
    ))

(defun anything-c-source-mark-ring-candidates ()
  (with-current-buffer anything-current-buffer
    (let* ((marks (cons (mark-marker) mark-ring))
           (lines (mapcar (lambda (pos)
                            (save-excursion
                              (goto-char pos)
                              (beginning-of-line)
                              (let ((line  (car (split-string (thing-at-point 'line) "[\n\r]"))))
                                (when (string= "" line)
                                  (setq line  "<EMPTY LINE>"))
                                (format "%7d: %s" (line-number-at-pos) line))))
                          marks)))
      lines
      )))


;; global-mark
(defvar anything-c-source-global-mark-ring
  '((name . "global-mark-ring")
    (candidates . anything-c-source-global-mark-ring-candidates)
    (action . (("Goto line" . (lambda (candidate)
                                (let ((items (split-string candidate ":")))
                                  (switch-to-buffer (second items))
                                  (goto-line (string-to-number (car items))))))))
    
    (persistent-action . (lambda (candidate)
                           (let ((items (split-string candidate ":")))
                             (switch-to-buffer (second items))
                             (goto-line (string-to-number (car items)))
                             (set-window-start (get-buffer-window anything-current-buffer) (point))
                             
                             (anything-persistent-highlight-point
                              (line-beginning-position)
                              (line-end-position)
                              (get-buffer (second items)))
                             )))
    ))

(defun anything-c-source-global-mark-ring-candidates ()
  (let* ((marks global-mark-ring)
         (lines (mapcar (lambda (pos)
                          (if (or (string-match "^ " (format "%s" (marker-buffer pos)))
                                  (null (marker-buffer pos)))
                              nil
                            (save-excursion
                              (set-buffer (marker-buffer pos))
                              (goto-char pos)
                              (beginning-of-line)
                              (let ((line  (car (split-string (thing-at-point 'line) "[\n\r]"))))
                                (when (string= "" line)
                                  (setq line  "<EMPTY LINE>"))
                                (format "%7d:%s:    %s" (line-number-at-pos) (marker-buffer pos) line)))))
                        marks)))
    (delq nil lines)))


; C-u C-SPC で anything-c-source-mark-ring 発動
(defadvice icicle-goto-marker-or-set-mark-command (around icicle-goto-mark-or-set-mark-command-take-over-anythig activate)
  (if (> (prefix-numeric-value (ad-get-arg 0)) 1)
      (anything '(anything-c-source-mark-ring
                  anything-c-source-global-mark-ring) nil "select mark: ")
    ad-do-it))
anything-c-persistent-highlight-point

これは、 persistent-actionを自動的に実行し、任意の箇所をハイライト - asdf から拝借したものです。
ラインの色付けに使用しているだけなので、不要な場合はコメントアウト