info-modeで使うanything(memo)

  • anything-c-moccurのように、selectionを移動するたびに対応した行に移動する方法がわかった。
(defmacro let1 (var val &rest body)
  (declare (indent 2) (debug t))
  `(let ((,var ,val))
     ,@body))
(defmacro ilambda (&rest body)
  `(lambda () (interactive) ,@body))

(defun info-view-find-node () (interactive)
  (and (re-search-forward "\\*.*:" nil t 1)
       (cons (match-string-no-properties 0) (match-beginning 0))))
  
(defun info-view-collect-node () (interactive)
    (save-excursion
      (goto-char (point-min))
      (let (acc)
	(while (setq e (info-view-find-node))
	  (push e acc))
	(nreverse acc))))

(defvar info-view-node-source nil)
(defun info-view-create-node-menu ()
  (setq info-view-node-source (info-view-collect-node)))

(defvar info-view-overlay-list nil)
(defun info-view-set-overlay (p)
  (let1 ov (make-overlay p (progn (re-search-forward ":" nil t 1) (point)))
    (push ov info-view-overlay-list)
    (overlay-put ov 'face 'region)
    (sit-for 3)
    (delete-overlay ov)))

;;この2つで視点移動さえできれば利便性がとても向上するのに。>できた。
(defadvice anything-next-line (after find-anything-pattern disable)
  (anything-scroll-other-window-base
   (ilambda (let1 p (anything-get-selection)
	      (goto-char p) (info-view-set-overlay p)))))

(defadvice anything-previous-line (after find-anything-pattern disable)
  (anything-scroll-other-window-base
   (ilambda (let1 p (anything-get-selection)
	      (goto-char p) (info-view-set-overlay p)))))

(defun info-view-menu-with-anything () (interactive)
  (ad-enable-advice 'anything-next-line 'after 'find-anything-pattern)
  (ad-activate 'anything-next-line)
  (ad-enable-advice 'anything-previous-line 'after 'find-anything-pattern)
  (ad-activate 'anything-previous-line)
  (unwind-protect
      (let ((source 
	     `((name . "link")
	       (init . info-view-create-node-menu)
	       (candidates . info-view-node-source)
	       (persistent-action . (lambda (c)
				      (with-current-buffer anything-current-buffer
					(goto-char c))))
	       (action . goto-char))))
	(anything (list source)))
    (dolist (ov info-view-overlay-list) (delete-overlay ov))
    (setq info-view-overlay-list nil)
    (ad-deactivate 'anything-previous-line)
    (ad-deactivate 'anything-next-line)))

(define-key Info-mode-map "o" 'info-view-menu-with-anything)