]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix octave-inf completion problems reported by Alexander Klimov.
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 25 Apr 2011 16:29:31 +0000 (13:29 -0300)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 25 Apr 2011 16:29:31 +0000 (13:29 -0300)
* lisp/progmodes/octave-inf.el (inferior-octave-mode-syntax-table):
Inherit from octave-mode-syntax-table.
(inferior-octave-mode): Set info-lookup-mode.
(inferior-octave-completion-at-point): New function.
(inferior-octave-complete): Use it and completion-in-region.
(inferior-octave-dynamic-complete-functions): Use it as well, and use
comint-filename-completion.
* lisp/progmodes/octave-mod.el (octave-mode-syntax-table): Use _ syntax for
symbol elements which shouldn't be word elements.
(octave-font-lock-keywords, octave-beginning-of-defun)
(octave-function-header-regexp): Adjust regexps accordingly.
(octave-mode-map): Also use info-lookup-symbol for C-c C-h.

lisp/ChangeLog
lisp/progmodes/octave-inf.el
lisp/progmodes/octave-mod.el

index 917fe6cf40a21848467185ea62317c7bab907887..ed4aafa0ef55da4eed8bb8d857ea82750cbdb8d5 100644 (file)
@@ -1,3 +1,19 @@
+2011-04-25  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       Fix octave-inf completion problems reported by Alexander Klimov.
+       * progmodes/octave-inf.el (inferior-octave-mode-syntax-table):
+       Inherit from octave-mode-syntax-table.
+       (inferior-octave-mode): Set info-lookup-mode.
+       (inferior-octave-completion-at-point): New function.
+       (inferior-octave-complete): Use it and completion-in-region.
+       (inferior-octave-dynamic-complete-functions): Use it as well, and use
+       comint-filename-completion.
+       * progmodes/octave-mod.el (octave-mode-syntax-table): Use _ syntax for
+       symbol elements which shouldn't be word elements.
+       (octave-font-lock-keywords, octave-beginning-of-defun)
+       (octave-function-header-regexp): Adjust regexps accordingly.
+       (octave-mode-map): Also use info-lookup-symbol for C-c C-h.
+
 2011-04-25  Juanma Barranquero  <lekktu@gmail.com>
 
        * net/gnutls.el (gnutls-errorp): Declare before first use.
@@ -32,8 +48,8 @@
        * finder.el (finder-list-matches): Use package-show-package-list
        instead of deleted package--list-packages.
 
-       * vc/vc-annotate.el (vc-annotate-goto-line): New command.  Based
-       on a previous implementation by Juanma Barranquero (Bug#8366).
+       * vc/vc-annotate.el (vc-annotate-goto-line): New command.
+       Based on a previous implementation by Juanma Barranquero (Bug#8366).
        (vc-annotate-mode-map): Bind it to RET.
 
 2011-04-24  Uday S Reddy  <u.s.reddy@cs.bham.ac.uk>  (tiny change)
index 239da3d8cd6d2d0d3216525a65968c7c807c7415..803a542563c51c452781eab36a42967da4725002 100644 (file)
@@ -73,10 +73,7 @@ mode, set this to (\"-q\" \"--traditional\")."
   "Keymap used in Inferior Octave mode.")
 
 (defvar inferior-octave-mode-syntax-table
-  (let ((table (make-syntax-table)))
-    (modify-syntax-entry ?\` "w" table)
-    (modify-syntax-entry ?\# "<" table)
-    (modify-syntax-entry ?\n ">" table)
+  (let ((table (make-syntax-table octave-mode-syntax-table)))
     table)
   "Syntax table in use in inferior-octave-mode buffers.")
 
@@ -115,11 +112,13 @@ the regular expression `comint-prompt-regexp', a buffer local variable."
   "Non-nil means that Octave has built-in variables.")
 
 (defvar inferior-octave-dynamic-complete-functions
-  '(inferior-octave-complete comint-dynamic-complete-filename)
+  '(inferior-octave-completion-at-point comint-filename-completion)
   "List of functions called to perform completion for inferior Octave.
 This variable is used to initialize `comint-dynamic-complete-functions'
 in the Inferior Octave buffer.")
 
+(defvar info-lookup-mode)
+
 (define-derived-mode inferior-octave-mode comint-mode "Inferior Octave"
   "Major mode for interacting with an inferior Octave process.
 Runs Octave as a subprocess of Emacs, with Octave I/O through an Emacs
@@ -139,6 +138,8 @@ Entry to this mode successively runs the hooks `comint-mode-hook' and
   (set (make-local-variable 'font-lock-defaults)
        '(inferior-octave-font-lock-keywords nil nil))
 
+  (set (make-local-variable 'info-lookup-mode) 'octave-mode)
+
   (setq comint-input-ring-file-name
        (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist")
        comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024))
@@ -259,39 +260,38 @@ startup file, `~/.emacs-octave'."
     (inferior-octave-resync-dirs)))
 
 \f
+(defun inferior-octave-completion-at-point ()
+  "Return the data to complete the Octave symbol at point."
+  (let* ((end (point))
+        (start
+         (save-excursion
+           (skip-syntax-backward "w_" (comint-line-beginning-position))
+            (point))))
+    (cond (inferior-octave-complete-impossible nil)
+         ((eq start end) nil)
+         (t
+           (list
+            start end
+            (completion-table-dynamic
+             (lambda (command)
+               (inferior-octave-send-list-and-digest
+                (list (concat "completion_matches (\"" command "\");\n")))
+               (sort (delete-dups inferior-octave-output-list)
+                     'string-lessp))))))))
+
 (defun inferior-octave-complete ()
   "Perform completion on the Octave symbol preceding point.
 This is implemented using the Octave command `completion_matches' which
 is NOT available with versions of Octave prior to 2.0."
   (interactive)
-  (let* ((end (point))
-        (command
-         (save-excursion
-           (skip-syntax-backward "w_" (comint-line-beginning-position))
-           (buffer-substring-no-properties (point) end))))
-    (cond (inferior-octave-complete-impossible
-          (error (concat
-                  "Your Octave does not have `completion_matches'.  "
-                  "Please upgrade to version 2.X.")))
-         ((string-equal command "")
-          (message "Cannot complete an empty string"))
-         (t
-          (inferior-octave-send-list-and-digest
-           (list (concat "completion_matches (\"" command "\");\n")))
-          ;; Sort the list
-          (setq inferior-octave-output-list
-                (sort inferior-octave-output-list 'string-lessp))
-          ;; Remove duplicates
-          (let* ((x inferior-octave-output-list)
-                 (y (cdr x)))
-            (while y
-              (if (string-equal (car x) (car y))
-                  (setcdr x (setq y (cdr y)))
-                (setq x y
-                      y (cdr y)))))
-          ;; And let comint handle the rest
-          (comint-dynamic-simple-complete
-           command inferior-octave-output-list)))))
+  (if inferior-octave-complete-impossible
+      (error (concat
+              "Your Octave does not have `completion_matches'.  "
+              "Please upgrade to version 2.X."))
+    (let ((data (inferior-octave-completion-at-point)))
+      (if (null data)
+          (message "Cannot complete an empty string")
+        (apply #'completion-in-region data)))))
 
 (defun inferior-octave-dynamic-list-input-ring ()
   "List the buffer's input history in a help buffer."
index 241928c8a1c12f5338c2c7fc99b4f4e9fd289c8b..39d997e1d5e7bc8c2cb3ef7382a0da805a580533 100644 (file)
@@ -150,8 +150,8 @@ All Octave abbrevs start with a grave accent (`)."
   "Builtin variables in Octave.")
 
 (defvar octave-function-header-regexp
-  (concat "^\\s-*\\<\\(function\\)\\>"
-         "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>")
+  (concat "^\\s-*\\_<\\(function\\)\\_>"
+         "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\(?:\\w\\|\\s_\\)+\\)\\_>")
   "Regexp to match an Octave function header.
 The string `function' and its name are given by the first and third
 parenthetical grouping.")
@@ -159,10 +159,10 @@ parenthetical grouping.")
 (defvar octave-font-lock-keywords
   (list
    ;; Fontify all builtin keywords.
-   (cons (concat "\\<\\("
+   (cons (concat "\\_<\\("
                 (regexp-opt (append octave-reserved-words
                                      octave-text-functions))
-                "\\)\\>")
+                "\\)\\_>")
         'font-lock-keyword-face)
    ;; Fontify all builtin operators.
    (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
@@ -170,7 +170,7 @@ parenthetical grouping.")
             'font-lock-builtin-face
           'font-lock-preprocessor-face))
    ;; Fontify all builtin variables.
-   (cons (concat "\\<" (regexp-opt octave-variables) "\\>")
+   (cons (concat "\\_<" (regexp-opt octave-variables) "\\_>")
         'font-lock-variable-name-face)
    ;; Fontify all function declarations.
    (list octave-function-header-regexp
@@ -223,7 +223,7 @@ parenthetical grouping.")
     (define-key map "\C-c]" 'smie-close-block)
     (define-key map "\C-c/" 'smie-close-block)
     (define-key map "\C-c\C-f" 'octave-insert-defun)
-    (define-key map "\C-c\C-h" 'octave-help)
+    (define-key map "\C-c\C-h" 'info-lookup-symbol)
     (define-key map "\C-c\C-il" 'octave-send-line)
     (define-key map "\C-c\C-ib" 'octave-send-block)
     (define-key map "\C-c\C-if" 'octave-send-defun)
@@ -299,8 +299,8 @@ parenthetical grouping.")
     ;; Was "w" for abbrevs, but now that it's not necessary any more,
     (modify-syntax-entry ?\` "."  table)
     (modify-syntax-entry ?\" "\"" table)
-    (modify-syntax-entry ?. "w"   table)
-    (modify-syntax-entry ?_ "w"   table)
+    (modify-syntax-entry ?. "_"   table)
+    (modify-syntax-entry ?_ "_"   table)
     ;; The "b" flag only applies to the second letter of the comstart
     ;; and the first letter of the comend, i.e. the "4b" below is ineffective.
     ;; If we try to put `b' on the single-line comments, we get a similar
@@ -818,11 +818,11 @@ Returns t unless search stops at the beginning or end of the buffer."
         (found nil)
          (case-fold-search nil))
     (and (not (eobp))
-        (not (and (> arg 0) (looking-at "\\<function\\>")))
+        (not (and (> arg 0) (looking-at "\\_<function\\_>")))
         (skip-syntax-forward "w"))
     (while (and (/= arg 0)
                (setq found
-                     (re-search-backward "\\<function\\>" inc)))
+                     (re-search-backward "\\_<function\\_>" inc)))
       (if (octave-not-in-string-or-comment-p)
          (setq arg (- arg inc))))
     (if found
@@ -975,12 +975,12 @@ otherwise."
 
 (defun octave-completion-at-point-function ()
   "Find the text to complete and the corresponding table."
-  (let* ((beg (save-excursion (backward-sexp 1) (point)))
+  (let* ((beg (save-excursion (skip-syntax-backward "w_") (point)))
          (end (point)))
     (if (< beg (point))
         ;; Extend region past point, if applicable.
-        (save-excursion (goto-char beg) (forward-sexp 1)
-                        (setq end (max end (point)))))
+        (save-excursion (skip-syntax-forward "w_")
+                        (setq end (point))))
     (list beg end octave-completion-alist)))
 
 (defun octave-complete-symbol ()