From: Leo Liu Date: Mon, 6 May 2013 23:46:07 +0000 (+0800) Subject: * progmodes/octave.el (octave-syntax-propertize-function): Change X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~276 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=203a557223f9e174268cd985aa15b5a593c94703;p=emacs.git * progmodes/octave.el (octave-syntax-propertize-function): Change \'s syntax to escape when inside double-quoted strings. (octave-font-lock-keywords): Use octave-operator-regexp. (octave-completion-at-point): Renamed from octave-completion-at-point-function. (inferior-octave-directory-tracker): Robustify. (octave-text-functions): Remove and fix its uses. No such things any more. Fixes: debbugs:14332 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b58d8b5e610..c4dbc803fcc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-05-06 Leo Liu + + * progmodes/octave.el (octave-syntax-propertize-function): Change + \'s syntax to escape when inside double-quoted strings. (Bug#14332) + (octave-font-lock-keywords): Use octave-operator-regexp. + (octave-completion-at-point): Renamed from + octave-completion-at-point-function. + (inferior-octave-directory-tracker): Robustify. + (octave-text-functions): Remove and fix its uses. No such things + any more. + 2013-05-06 Stefan Monnier * emacs-lisp/trace.el (trace--display-buffer): New function. diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index a2d494f0497..ebefcef0c71 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -84,13 +84,6 @@ Used in `octave-mode' and `inferior-octave-mode' buffers.") '("break" "continue" "end" "global" "persistent" "return")) "Reserved words in Octave.") -(defvar octave-text-functions - '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo" - "edit_history" "format" "help" "history" "hold" - "load" "ls" "more" "run_history" "save" "type" - "which" "who" "whos") - "Text functions in Octave.") - (defvar octave-function-header-regexp (concat "^\\s-*\\_<\\(function\\)\\_>" "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\(?:\\w\\|\\s_\\)+\\)\\_>") @@ -98,64 +91,6 @@ Used in `octave-mode' and `inferior-octave-mode' buffers.") 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 "\\_<\\(" - (regexp-opt (append octave-reserved-words - octave-text-functions)) - "\\)\\_>") - 'font-lock-keyword-face) - ;; Note: 'end' also serves as the last index in an indexing expression. - ;; Ref: http://www.mathworks.com/help/matlab/ref/end.html - (list (lambda (limit) - (while (re-search-forward "\\_" limit 'move) - (let ((beg (match-beginning 0)) - (end (match-end 0))) - (unless (octave-in-string-or-comment-p) - (unwind-protect - (progn - (goto-char beg) - (backward-up-list) - (when (memq (char-after) '(?\( ?\[ ?\{)) - (put-text-property beg end 'face nil))) - (goto-char end))))) - nil)) - ;; Fontify all builtin operators. - (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)" - (if (boundp 'font-lock-builtin-face) - 'font-lock-builtin-face - 'font-lock-preprocessor-face)) - ;; Fontify all function declarations. - (list octave-function-header-regexp - '(1 font-lock-keyword-face) - '(3 font-lock-function-name-face nil t))) - "Additional Octave expressions to highlight.") - -(defun octave-syntax-propertize-function (start end) - (goto-char start) - (octave-syntax-propertize-sqs end) - (funcall (syntax-propertize-rules - ;; Try to distinguish the string-quotes from the transpose-quotes. - ("\\(?:^\\|[[({,; ]\\)\\('\\)" - (1 (prog1 "\"'" (octave-syntax-propertize-sqs end))))) - (point) end)) - -(defun octave-syntax-propertize-sqs (end) - "Propertize the content/end of single-quote strings." - (when (eq (nth 3 (syntax-ppss)) ?\') - ;; A '..' string. - (when (re-search-forward - "\\(?:\\=\\|[^']\\)\\(?:''\\)*\\('\\)\\($\\|[^']\\)" end 'move) - (goto-char (match-beginning 2)) - (when (eq (char-before (match-beginning 1)) ?\\) - ;; Backslash cannot escape a single quote. - (put-text-property (1- (match-beginning 1)) (match-beginning 1) - 'syntax-table (string-to-syntax "."))) - (put-text-property (match-beginning 1) (match-end 1) - 'syntax-table (string-to-syntax "\"'"))))) - (defvar octave-mode-map (let ((map (make-sparse-keymap))) @@ -333,6 +268,7 @@ Non-nil means always go to the next Octave code line after sending." (require 'smie) +;; Use '__operators__' in Octave REPL to get a full list. (defconst octave-operator-table '((assoc ";" "\n") (assoc ",") ; The doc claims they have equal precedence!? (right "=" "+=" "-=" "*=" "/=") @@ -476,6 +412,64 @@ Non-nil means always go to the next Octave code line after sending." ;; (if (smie-parent-p "switch") 4) 0)))) + +(defvar octave-font-lock-keywords + (list + ;; Fontify all builtin keywords. + (cons (concat "\\_<\\(" + (regexp-opt octave-reserved-words) + "\\)\\_>") + 'font-lock-keyword-face) + ;; Note: 'end' also serves as the last index in an indexing expression. + ;; Ref: http://www.mathworks.com/help/matlab/ref/end.html + (list (lambda (limit) + (while (re-search-forward "\\_" limit 'move) + (let ((beg (match-beginning 0)) + (end (match-end 0))) + (unless (octave-in-string-or-comment-p) + (unwind-protect + (progn + (goto-char beg) + (backward-up-list) + (when (memq (char-after) '(?\( ?\[ ?\{)) + (put-text-property beg end 'face nil))) + (goto-char end))))) + nil)) + ;; Fontify all operators. + (cons octave-operator-regexp 'font-lock-builtin-face) + ;; Fontify all function declarations. + (list octave-function-header-regexp + '(1 font-lock-keyword-face) + '(3 font-lock-function-name-face nil t))) + "Additional Octave expressions to highlight.") + +(defun octave-syntax-propertize-function (start end) + (goto-char start) + (octave-syntax-propertize-sqs end) + (funcall (syntax-propertize-rules + ("\\\\" (0 (when (eq (nth 3 (save-excursion + (syntax-ppss (match-beginning 0)))) + ?\") + (string-to-syntax "\\")))) + ;; Try to distinguish the string-quotes from the transpose-quotes. + ("\\(?:^\\|[[({,; ]\\)\\('\\)" + (1 (prog1 "\"'" (octave-syntax-propertize-sqs end))))) + (point) end)) + +(defun octave-syntax-propertize-sqs (end) + "Propertize the content/end of single-quote strings." + (when (eq (nth 3 (syntax-ppss)) ?\') + ;; A '..' string. + (when (re-search-forward + "\\(?:\\=\\|[^']\\)\\(?:''\\)*\\('\\)\\($\\|[^']\\)" end 'move) + (goto-char (match-beginning 2)) + (when (eq (char-before (match-beginning 1)) ?\\) + ;; Backslash cannot escape a single quote. + (put-text-property (1- (match-beginning 1)) (match-beginning 1) + 'syntax-table (string-to-syntax "."))) + (put-text-property (match-beginning 1) (match-end 1) + 'syntax-table (string-to-syntax "\"'"))))) + (defvar electric-layout-rules) ;;;###autoload @@ -530,8 +524,7 @@ definitions can also be stored in files and used in batch mode." (setq-local imenu-generic-expression octave-mode-imenu-generic-expression) (setq-local imenu-case-fold-search nil) - (add-hook 'completion-at-point-functions - 'octave-completion-at-point-function nil t) + (add-hook 'completion-at-point-functions 'octave-completion-at-point nil t) (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) (setq-local beginning-of-defun-function 'octave-beginning-of-defun) (and octave-font-lock-texinfo-comment (octave-font-lock-texinfo-comment)) @@ -647,7 +640,7 @@ in the Inferior Octave buffer.") inferior-octave-dynamic-complete-functions) (setq-local comint-prompt-read-only inferior-octave-prompt-read-only) (add-hook 'comint-input-filter-functions - 'inferior-octave-directory-tracker nil t) + 'inferior-octave-directory-tracker nil t) (comint-read-input-ring t)) ;;;###autoload @@ -828,7 +821,8 @@ Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." ((string-match "^[ \t]*cd[ \t;]*$" string) (cd "~")) ((string-match "^[ \t]*cd[ \t]+\\([^ \t\n;]*\\)[ \t\n;]*" string) - (cd (substring string (match-beginning 1) (match-end 1)))))) + (with-demoted-errors ; in case directory doesn't exist + (cd (substring string (match-beginning 1) (match-end 1))))))) (defun inferior-octave-resync-dirs () "Resync the buffer's idea of the current directory. @@ -1308,7 +1302,7 @@ otherwise." ;;; Completions -(defun octave-completion-at-point-function () +(defun octave-completion-at-point () "Find the text to complete and the corresponding table." (let* ((beg (save-excursion (skip-syntax-backward "w_") (point))) (end (point))) @@ -1316,11 +1310,11 @@ otherwise." ;; Extend region past point, if applicable. (save-excursion (skip-syntax-forward "w_") (setq end (point)))) - (list beg end (or (and inferior-octave-process - (process-live-p inferior-octave-process) - (inferior-octave-completion-table)) - (append octave-reserved-words - octave-text-functions))))) + (when (> end beg) + (list beg end (or (and inferior-octave-process + (process-live-p inferior-octave-process) + (inferior-octave-completion-table)) + octave-reserved-words))))) (define-obsolete-function-alias 'octave-complete-symbol 'completion-at-point "24.1")