From b4da2cbb0d5d5d7315b13f9bf7ad445d948caac2 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Tue, 21 May 2013 06:52:40 +0800 Subject: [PATCH] Use octave-help-mode for the Octave Help buffer --- lisp/ChangeLog | 7 ++++++ lisp/progmodes/octave.el | 48 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8fcd7424401..c70f156bf45 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-05-20 Leo Liu + + * progmodes/octave.el (octave-help-mode-map) + (octave-help-mode-finish-hook): New variables. + (octave-help-mode, octave-help-mode-finish): New functions. + (octave-help): Use octave-help-mode. + 2013-05-20 Glenn Morris * format-spec.el (format-spec): Allow spec chars with nil. (Bug#14420) diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index df03251bbc9..4f1e6c2cc14 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -1587,14 +1587,54 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n" (octave-help (buffer-substring (button-start b) (button-end b))))) -(defvar help-xref-following) +(defvar octave-help-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "\M-." 'octave-find-definition) + (define-key map "\C-hd" 'octave-help) + map)) + +(define-derived-mode octave-help-mode help-mode "OctHelp" + "Major mode for displaying Octave documentation." + :abbrev-table nil + :syntax-table octave-mode-syntax-table + (eval-and-compile (require 'help-mode)) + ;; Mostly stolen from `help-make-xrefs'. + (let ((inhibit-read-only t)) + (setq-local info-lookup-mode 'octave-mode) + ;; Delete extraneous newlines at the end of the docstring + (goto-char (point-max)) + (while (and (not (bobp)) (bolp)) + (delete-char -1)) + (insert "\n") + (when (or help-xref-stack help-xref-forward-stack) + (insert "\n")) + (when help-xref-stack + (help-insert-xref-button help-back-label 'help-back + (current-buffer))) + (when help-xref-forward-stack + (when help-xref-stack + (insert "\t")) + (help-insert-xref-button help-forward-label 'help-forward + (current-buffer))) + (when (or help-xref-stack help-xref-forward-stack) + (insert "\n")))) + +(defvar octave-help-mode-finish-hook nil + "Octave specific hook for `temp-buffer-show-hook'.") + +(defun octave-help-mode-finish () + (when (eq major-mode 'octave-help-mode) + (run-hooks 'octave-help-mode-finish-hook))) + +(add-hook 'temp-buffer-show-hook 'octave-help-mode-finish) (defun octave-help (fn) "Display the documentation of FN." (interactive (list (octave-completing-read))) (inferior-octave-send-list-and-digest (list (format "help \"%s\"\n" fn))) - (let ((lines inferior-octave-output-list)) + (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 @@ -1605,7 +1645,6 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n" (let ((help-xref-following t)) (help-setup-xref (list 'octave-help fn) (called-interactively-p 'interactive))) - (setq-local info-lookup-mode 'octave-mode) ;; Note: can be turned off by suppress_verbose_help_message. ;; ;; Remove boring trailing text: Additional help for built-in functions @@ -1631,7 +1670,8 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n" (while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t) (make-text-button (match-beginning 0) (match-end 0) - :type 'octave-help-function)))))))) + :type 'octave-help-function)))) + (octave-help-mode))))) (defcustom octave-source-directories nil "A list of directories for Octave sources. -- 2.39.2