emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r112486: * progmodes/octave.el (octav


From: Leo Liu
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112486: * progmodes/octave.el (octave-syntax-propertize-function): Change
Date: Tue, 07 May 2013 07:46:07 +0800
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112486
fixes bug: http://debbugs.gnu.org/14332
committer: Leo Liu <address@hidden>
branch nick: trunk
timestamp: Tue 2013-05-07 07:46:07 +0800
message:
  * 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.
modified:
  lisp/ChangeLog
  lisp/progmodes/octave.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-05-06 22:33:24 +0000
+++ b/lisp/ChangeLog    2013-05-06 23:46:07 +0000
@@ -1,3 +1,14 @@
+2013-05-06  Leo Liu  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/trace.el (trace--display-buffer): New function.

=== modified file 'lisp/progmodes/octave.el'
--- a/lisp/progmodes/octave.el  2013-05-06 02:29:42 +0000
+++ b/lisp/progmodes/octave.el  2013-05-06 23:46:07 +0000
@@ -84,13 +84,6 @@
          '("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_\\)+\\)\\_>")
@@ -99,64 +92,6 @@
 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 "\\_<end\\_>" 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)))
     (define-key map "\M-." 'octave-find-definition)
@@ -333,6 +268,7 @@
 
 (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 @@
        ;; (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 "\\_<end\\_>" 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 @@
   (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 @@
               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 @@
    ((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 @@
 
 ;;; 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 @@
         ;; 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")


reply via email to

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