]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/octave.el
* lisp/emacs-lisp/smie.el (smie-highlight-matching-block): Always turn
[gnu-emacs] / lisp / progmodes / octave.el
index 6469abfe43f9f0714d48edcb45192ce146fd94b4..bacd37b3d3cc22304c33a57672a29fd7c84c0fe8 100644 (file)
@@ -438,7 +438,7 @@ Non-nil means always go to the next Octave code line after sending."
          (smie-rule-parent octave-block-offset)
        ;; For (invalid) code between switch and case.
        ;; (if (smie-parent-p "switch") 4)
-       0))))
+       nil))))
 
 (defun octave-indent-comment ()
   "A function for `smie-indent-functions' (which see)."
@@ -446,11 +446,11 @@ Non-nil means always go to the next Octave code line after sending."
     (back-to-indentation)
     (cond
      ((octave-in-string-or-comment-p) nil)
-     ((looking-at-p "\\s<\\{3,\\}")
+     ((looking-at-p "\\(\\s<\\)\\1\\{2,\\}")
       0)
      ;; Exclude %{, %} and %!.
      ((and (looking-at-p "\\s<\\(?:[^{}!]\\|$\\)")
-           (not (looking-at-p "\\s<\\s<")))
+           (not (looking-at-p "\\(\\s<\\)\\1")))
       (comment-choose-indent)))))
 
 \f
@@ -552,11 +552,10 @@ definitions can also be stored in files and used in batch mode."
   (setq-local paragraph-ignore-fill-prefix t)
   (setq-local fill-paragraph-function 'octave-fill-paragraph)
 
-  ;; Use `smie-auto-fill' after fixing bug#14381.
-  (setq-local normal-auto-fill-function 'do-auto-fill)
   (setq-local fill-nobreak-predicate
               (lambda () (eq (octave-in-string-p) ?')))
-  (setq-local comment-line-break-function #'octave-indent-new-comment-line)
+  (add-function :around (local 'comment-line-break-function)
+                #'octave--indent-new-comment-line)
 
   (setq font-lock-defaults '(octave-font-lock-keywords))
 
@@ -770,20 +769,17 @@ startup file, `~/.emacs-octave'."
            (when (and inferior-octave-startup-file
                       (file-exists-p inferior-octave-startup-file))
              (format "source (\"%s\");\n" inferior-octave-startup-file))))
-    (insert-before-markers
-     (concat
-      (if inferior-octave-output-list
-          (concat (mapconcat
-                   'identity inferior-octave-output-list "\n")
-                  "\n"))
-      inferior-octave-output-string))
+    (when inferior-octave-output-list
+      (insert-before-markers
+       (mapconcat 'identity inferior-octave-output-list "\n")))
 
     ;; And finally, everything is back to normal.
     (set-process-filter proc 'comint-output-filter)
     ;; Just in case, to be sure a cd in the startup file
     ;; won't have detrimental effects.
     (inferior-octave-resync-dirs)
-    ;; A trick to get the prompt highlighted.
+    ;; Generate a proper prompt, which is critical to
+    ;; `comint-history-isearch-backward-regexp'.  Bug#14433.
     (comint-send-string proc "\n")))
 
 (defvar inferior-octave-completion-table
@@ -889,15 +885,25 @@ output is passed to the filter `inferior-octave-output-digest'."
          (setq list (cdr list)))
       (set-process-filter proc filter))))
 
+(defvar inferior-octave-directory-tracker-resync nil)
+(make-variable-buffer-local 'inferior-octave-directory-tracker-resync)
+
 (defun inferior-octave-directory-tracker (string)
   "Tracks `cd' commands issued to the inferior Octave process.
 Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
+  (when inferior-octave-directory-tracker-resync
+    (setq inferior-octave-directory-tracker-resync nil)
+    (inferior-octave-resync-dirs))
   (cond
    ((string-match "^[ \t]*cd[ \t;]*$" string)
     (cd "~"))
    ((string-match "^[ \t]*cd[ \t]+\\([^ \t\n;]*\\)[ \t\n;]*" string)
-    (with-demoted-errors             ; in case directory doesn't exist
-      (cd (substring string (match-beginning 1) (match-end 1)))))))
+    (condition-case err
+        (cd (match-string 1 string))
+      (error (setq inferior-octave-directory-tracker-resync t)
+             (message "%s: `%s'"
+                      (error-message-string err)
+                      (match-string 1 string)))))))
 
 (defun inferior-octave-resync-dirs ()
   "Resync the buffer's idea of the current directory.
@@ -1115,11 +1121,16 @@ q: Don't fix\n" func file))
 ;;; Indentation
 
 (defun octave-indent-new-comment-line (&optional soft)
+  ;; FIXME: C-M-j should probably be bound globally to a function like
+  ;; this one.
   "Break Octave line at point, continuing comment if within one.
 Insert `octave-continuation-string' before breaking the line
 unless inside a list.  Signal an error if within a single-quoted
 string."
   (interactive)
+  (funcall comment-line-break-function soft))
+
+(defun octave--indent-new-comment-line (orig &rest args)
   (cond
    ((octave-in-comment-p) nil)
    ((eq (octave-in-string-p) ?')
@@ -1131,7 +1142,7 @@ string."
     (unless (and (cadr (syntax-ppss))
                  (eq (char-after (cadr (syntax-ppss))) ?\())
       (insert " " octave-continuation-string))))
-  (indent-new-comment-line soft)
+  (apply orig args)
   (indent-according-to-mode))
 
 (define-obsolete-function-alias
@@ -1626,10 +1637,14 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n"
         ;; Make 'See also' clickable
         (with-syntax-table octave-mode-syntax-table
           (when (re-search-forward "^\\s-*See also:" nil t)
-            (while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t)
-              (make-text-button (match-beginning 0)
-                                (match-end 0)
-                                :type 'octave-help-function))))
+            (let ((end (save-excursion (re-search-forward "^\\s-*$" nil t))))
+              (while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" end t)
+                (make-text-button (match-beginning 0)
+                                  ;; If the match ends with . exclude it.
+                                  (if (eq (char-before (match-end 0)) ?.)
+                                      (1- (match-end 0))
+                                    (match-end 0))
+                                  :type 'octave-help-function)))))
         (octave-help-mode)))))
 
 (defcustom octave-source-directories nil