emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104006: Fix octave-inf completion pr


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104006: Fix octave-inf completion problems reported by Alexander Klimov.
Date: Mon, 25 Apr 2011 13:29:31 -0300
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104006
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Mon 2011-04-25 13:29:31 -0300
message:
  Fix octave-inf completion problems reported by Alexander Klimov.
  * 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.
modified:
  lisp/ChangeLog
  lisp/progmodes/octave-inf.el
  lisp/progmodes/octave-mod.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-04-25 13:47:23 +0000
+++ b/lisp/ChangeLog    2011-04-25 16:29:31 +0000
@@ -1,3 +1,19 @@
+2011-04-25  Stefan Monnier  <address@hidden>
+
+       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  <address@hidden>
 
        * 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  <address@hidden>  (tiny change)

=== modified file 'lisp/progmodes/octave-inf.el'
--- a/lisp/progmodes/octave-inf.el      2011-04-22 18:44:26 +0000
+++ b/lisp/progmodes/octave-inf.el      2011-04-25 16:29:31 +0000
@@ -73,10 +73,7 @@
   "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 @@
   "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 @@
   (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 @@
     (inferior-octave-resync-dirs)))
 
 
+(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."

=== modified file 'lisp/progmodes/octave-mod.el'
--- a/lisp/progmodes/octave-mod.el      2011-04-22 18:44:26 +0000
+++ b/lisp/progmodes/octave-mod.el      2011-04-25 16:29:31 +0000
@@ -150,8 +150,8 @@
   "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 @@
 (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 @@
             '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 @@
     (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 @@
     ;; 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 @@
         (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 @@
 
 (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 ()


reply via email to

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