[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] octave.el: Add `octave-apropos' function.

From: Rüdiger Sonderfeld
Subject: [PATCH 2/3] octave.el: Add `octave-apropos' function.
Date: Fri, 27 Sep 2013 15:11:28 +0200
User-agent: KMail/4.10.5 (Linux/3.8.0-30-generic; KDE/4.10.5; x86_64; ; )

It searches help strings ("lookfor") of octave functions.

* lisp/progmodes/octave.el (octave-mode-map): Add key binding for
  (octave-mode-menu): Add menu entry for `octave-apropos'.
  (inferior-octave-mode-map): Add key binding for `octave-apropos'.
  (octave-help-mode-map): Add key binding for  `octave-apropos'.
  (octave-apropos): New function.
  (octave-lookfor): New alias.

Signed-off-by: Rüdiger Sonderfeld <address@hidden>
 lisp/progmodes/octave.el | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index c5710b8..ba500d6 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -109,6 +109,7 @@ (defvar octave-mode-map
     (define-key map "\C-c/" 'smie-close-block)
     (define-key map "\C-c;" 'octave-update-function-file-comment)
     (define-key map "\C-hd" 'octave-help)
+    (define-key map "\C-ha" 'octave-apropos)
     (define-key map "\C-c\C-f" 'octave-insert-defun)
     (define-key map "\C-c\C-il" 'octave-send-line)
     (define-key map "\C-c\C-ib" 'octave-send-block)
@@ -145,6 +146,7 @@ (easy-menu-define octave-mode-menu octave-mode-map
     ["Start Octave Process"         run-octave t]
     ["Documentation Lookup"         info-lookup-symbol t]
     ["Help on Function"             octave-help t]
+    ["Search help"                  octave-apropos t]
     ["Find Function Definition"     octave-find-definition t]
     ["Insert Function"              octave-insert-defun t]
     ["Update Function File Comment" octave-update-function-file-comment t]
@@ -637,6 +639,7 @@ (defvar inferior-octave-mode-map
     (define-key map "\M-." 'octave-find-definition)
     (define-key map "\t" 'completion-at-point)
     (define-key map "\C-hd" 'octave-help)
+    (define-key map "\C-ha" 'octave-apropos)
     ;; Same as in `shell-mode'.
     (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
     (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring)
@@ -1607,6 +1610,7 @@ (defvar octave-help-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\M-." 'octave-find-definition)
     (define-key map "\C-hd" 'octave-help)
+    (define-key map "\C-ha" 'octave-apropos)
 (define-derived-mode octave-help-mode help-mode "OctHelp"
@@ -1685,6 +1689,34 @@ (defun octave-help (fn)
                                   :type 'octave-help-function)))))
+(defun octave-apropos (str &optional all)
+  "Search for the string STR in all function help strings.
+If ALL is non-nil search the entire help string else only search the first
+  (interactive "sSearch for: \nP")
+  (inferior-octave-send-list-and-digest
+   (list (format "lookfor (%s'%s');\n"
+                 (if all "'-all', " "")
+                 str)))
+  (let ((lines inferior-octave-output-list)
+        (inhibit-read-only t))
+    (when (string-match "error: \\(.*\\)$" (car lines))
+      (error "%s" (match-string 1 (car lines))))
+    (with-help-window octave-help-buffer
+      (princ (mapconcat 'identity lines "\n"))
+      (with-current-buffer octave-help-buffer
+        ;; Bound to t so that `help-buffer' returns current buffer for
+        ;; `help-setup-xref'.
+        (let ((help-xref-following t))
+          (help-setup-xref (list 'octave-apropos str all)
+                           (called-interactively-p 'interactive)))
+        (goto-char (point-min))
+        (while (re-search-forward "^\\([^[:blank:]]+\\) " nil 'noerror)
+          (make-text-button (match-beginning 1) (match-end 1)
+                            :type 'octave-help-function))
+        (octave-help-mode)))))
+(defalias 'octave-lookfor #'octave-apropos)
 (defcustom octave-source-directories nil
   "A list of directories for Octave sources.
 If the environment variable OCTAVE_SRCDIR is set, it is searched first."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]