;;; Info (provide 'anything-c-info) (eval-after-load "info.el" (progn (defvar anything-c-info-menu-items-candidates nil "Keep xref anchor info.") (defun anything-c-info-build-candidate (builder) "Traverse info buffer to build candidates list. BUILDER is called with one argument. The argument is the beginning point of Info xref. BUILDER shoule return anything candidate formatted of (DISPLAY . REAL). see `anything-sources'" (with-current-buffer anything-current-buffer (save-excursion (setq anything-c-info-menu-items-candidates nil) (goto-char (point-min)) (let ((prev-position (point-min)) cur ret) (while (<= prev-position (setq cur (point))) (push (funcall builder cur) anything-c-info-menu-items-candidates) (setq prev-position cur) (Info-next-reference))) (setq anything-c-info-menu-items-candidates (cdr (reverse anything-c-info-menu-items-candidates)))))) (defvar anything-c-source-info-menu-items '((name . "Info xrefs") (init . (lambda () (anything-c-info-build-candidate (lambda (p) (cons (buffer-substring p (next-char-property-change p)) p))))) (candidates . (lambda () anything-c-info-menu-items-candidates)) (persistent-action . (lambda (p) (goto-char p) (anything-persistent-highlight-point p) (next-char-property-change p))) (action . (("goto" . (lambda (p) (goto-char p) (Info-follow-nearest-node))) ("View in new Info buffer" . (lambda (p) (goto-char p) (Info-follow-nearest-node t)))))) "Info-menu with anything") (defun anything-c-source-info-index-initialize () (with-current-buffer anything-current-buffer (Info-goto-index) (anything-c-info-build-candidate (lambda (p) (cons (buffer-substring p (next-char-property-change p)) p))) (Info-history-back))) (defun anything-c-source-info-index-goto-node (p &optional fork) (Info-goto-index) (goto-char p) (Info-follow-nearest-node fork) (pop Info-history)) (defvar anything-c-source-info-index '((name . "Info xrefs") (init . anything-c-source-info-index-initialize) (candidates . (lambda () anything-c-info-menu-items-candidates)) (persistent-action . (lambda (p) (anything-c-source-info-index-goto-node p) (pop Info-history))) (explicit-persistent-action . t) (action . (("goto" . (lambda (p) (anything-c-source-info-index-goto-node p))) ("View in new Info buffer" . (lambda (p) (anything-c-source-info-index-goto-node p t)))))) "Info-index with anything") (add-hook 'Info-mode-hook (lambda () (define-key Info-mode-map "m" (anything-with-sources anything-c-source-info-menu-items)) (define-key Info-mode-map "i" (anything-with-sources anything-c-source-info-index)))) (defvar anything-c-source-info-apropos '((name . "Info Appropos") (candidates . (lambda () (apply 'start-process "info apropos" nil (funcall anything-c-source-info-apropos-command anything-pattern) ))) (type . string) (action . (("info" . (lambda (c) (string-match "\"\\(.*\\)\"" c) (info (match-string 1 c)))))) (requires-pattern . 3) (delayed)) "Info apropos") (defvar anything-c-source-info-apropos-command (lambda (query) (list "info" (concat "--apropos=" query))) "the Procedure that is called with one argument. ") (defvar anything-c-source-info-apropos-command (lambda (query) (append (list "apropos.sh" query)))) (defun anything-info-apropos () (interactive) (funcall (anything-with-sources anything-c-source-info-apropos))) (defvar anything-c-source-man-apropos '((name . "Man apropos") (candidates . anything-c-source-man-apropos-candidates) (type . string) (requires-pattern . 3) (action . (("man" . (lambda (c) (let ((ret (string-match "^\\([^[:space:]]+\\) +(\\([[:alnum:]]+\\))" c))) (woman (match-string 1 c))))))))) (defun anything-c-source-man-apropos-candidates () (apply 'start-process "man apropos" nil (funcall anything-c-source-man-apropos-command (substring-no-properties anything-pattern)))) (defvar anything-c-source-man-apropos-command (lambda (query) (list "man" "-k" query))) (defun anything-man-apropos () (interactive) (funcall (anything-with-sources anything-c-source-man-apropos)))))