+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.
* 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)
"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.")
"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
(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))
(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."
"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.")
(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 "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
'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
(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)
;; 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
(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
(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 ()