all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH 2/3] octave.el: Add `octave-apropos' function.
@ 2013-09-27 13:11 Rüdiger Sonderfeld
  2013-09-28  0:31 ` Stefan Monnier
  2013-09-28  2:32 ` Leo Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Rüdiger Sonderfeld @ 2013-09-27 13:11 UTC (permalink / raw)
  To: emacs-devel; +Cc: Leo Liu

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





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] octave.el: Add `octave-apropos' function.
  2013-09-27 13:11 [PATCH 2/3] octave.el: Add `octave-apropos' function Rüdiger Sonderfeld
@ 2013-09-28  0:31 ` Stefan Monnier
  2013-09-28  2:32 ` Leo Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2013-09-28  0:31 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: Leo Liu, emacs-devel

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

Looks good overall.  See comments below.

> +  (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)))))

Please move the inhibit-read-only binding closer to the actual
buffer modifications.  Especially, binding it in one buffer to then
use it in another is a very bad idea.


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] octave.el: Add `octave-apropos' function.
  2013-09-27 13:11 [PATCH 2/3] octave.el: Add `octave-apropos' function Rüdiger Sonderfeld
  2013-09-28  0:31 ` Stefan Monnier
@ 2013-09-28  2:32 ` Leo Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Leo Liu @ 2013-09-28  2:32 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: emacs-devel

On 2013-09-27 21:11 +0800, Rüdiger Sonderfeld wrote:
> It searches help strings ("lookfor") of octave functions.

Thanks. Merged with small tweaks.

Leo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-28  2:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-27 13:11 [PATCH 2/3] octave.el: Add `octave-apropos' function Rüdiger Sonderfeld
2013-09-28  0:31 ` Stefan Monnier
2013-09-28  2:32 ` Leo Liu

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.