all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Rüdiger Sonderfeld" <ruediger@c-plusplus.de>
To: emacs-devel@gnu.org
Cc: Leo Liu <sdl.web@gmail.com>
Subject: [PATCH 2/3] octave.el: Add `octave-apropos' function.
Date: Fri, 27 Sep 2013 15:11:28 +0200	[thread overview]
Message-ID: <2808254.TOFES3Zzvm@descartes> (raw)

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

* lisp/progmodes/octave.el (octave-mode-map): Add key binding for
  `octave-apropos'.
  (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 <ruediger@c-plusplus.de>
---
 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)
     map))
 
 (define-derived-mode octave-help-mode help-mode "OctHelp"
@@ -1685,6 +1689,34 @@ (defun octave-help (fn)
                                   :type 'octave-help-function)))))
         (octave-help-mode)))))
 
+(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
+sentence."
+  (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."
-- 
1.8.4





             reply	other threads:[~2013-09-27 13:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 13:11 Rüdiger Sonderfeld [this message]
2013-09-28  0:31 ` [PATCH 2/3] octave.el: Add `octave-apropos' function Stefan Monnier
2013-09-28  2:32 ` Leo Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2808254.TOFES3Zzvm@descartes \
    --to=ruediger@c-plusplus.de \
    --cc=emacs-devel@gnu.org \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.