summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2021-02-10 01:30:08 +0000
committerBasil L. Contovounesios <contovob@tcd.ie>2021-02-11 14:35:47 +0000
commit21ec45c10727403421c41c8c67a752458790afbb (patch)
tree7e1071b3c10f2135409a851bc525fe5be26b9e75
parent0e2b123a4ef600f5b337972a7bb61c1fc4b7d0cd (diff)
downloademacs-21ec45c10727403421c41c8c67a752458790afbb.tar.gz
Fix Octave double-quoted string line continuations
* lisp/progmodes/octave.el (octave-string-continuation-marker): New defconst after octave-continuation-string. (octave-continuation-string): Mention it in docstring. (octave-maybe-insert-continuation-string): Mark unused function as obsolete. (octave-help-function): Simplify action. (octave--indent-new-comment-line): Insert octave-string-continuation-marker instead of octave-continuation-string within double-quoted strings (bug#46420). (octave-indent-new-comment-line): * etc/NEWS: Describe new behavior.
-rw-r--r--doc/misc/octave-mode.texi5
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/progmodes/octave.el49
3 files changed, 39 insertions, 24 deletions
diff --git a/doc/misc/octave-mode.texi b/doc/misc/octave-mode.texi
index 1adc2689697..e3306060159 100644
--- a/doc/misc/octave-mode.texi
+++ b/doc/misc/octave-mode.texi
@@ -83,9 +83,12 @@ addition to the standard Emacs commands.
@kindex C-M-j
@findex octave-indent-new-comment-line
@vindex octave-continuation-string
+@vindex octave-string-continuation-marker
Break Octave line at point, continuing comment if within one. Insert
@code{octave-continuation-string} before breaking the line unless
-inside a list. Signal an error if within a single-quoted string.
+inside a list. If within a double-quoted string, insert
+@code{octave-string-continuation-marker} instead. Signal an error if
+within a single-quoted string.
@item C-c ;
@kindex C-c ;
diff --git a/etc/NEWS b/etc/NEWS
index 67fc49f1817..2f15f078a75 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2018,6 +2018,15 @@ could have saved enough typing by using an abbrev, a hint will be
displayed in the echo area, mentioning the abbrev that could have been
used instead.
+** Octave Mode
+
++++
+*** Line continuations in double-quoted strings now use a backslash.
+Typing 'C-M-j' (bound to 'octave-indent-new-comment-line') now follows
+the behavior introduced in Octave 3.8 of using a backslash as a line
+continuation marker within double-quoted strings, and an ellipsis
+everywhere else.
+
* New Modes and Packages in Emacs 28.1
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index ddcc6f5450e..a8a86478d8b 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -215,9 +215,15 @@ newline or semicolon after an else or end keyword."
(concat "[^#%\n]*\\(" octave-continuation-marker-regexp
"\\)\\s-*\\(\\s<.*\\)?$"))
-;; Char \ is considered a bad decision for continuing a line.
(defconst octave-continuation-string "..."
- "Character string used for Octave continuation lines.")
+ "Character string used for Octave continuation lines.
+Joins current line with following line, except within
+double-quoted strings, where `octave-string-continuation-marker'
+is used instead.")
+
+(defconst octave-string-continuation-marker "\\"
+ "Line continuation marker for double-quoted Octave strings.
+Non-string statements use `octave-continuation-string'.")
(defvar octave-mode-imenu-generic-expression
(list
@@ -1032,11 +1038,11 @@ directory and makes this the current buffer's default directory."
(looking-at regexp)))
(defun octave-maybe-insert-continuation-string ()
- (if (or (octave-in-comment-p)
- (save-excursion
- (beginning-of-line)
- (looking-at octave-continuation-regexp)))
- nil
+ (declare (obsolete nil "28.1"))
+ (unless (or (octave-in-comment-p)
+ (save-excursion
+ (beginning-of-line)
+ (looking-at octave-continuation-regexp)))
(delete-horizontal-space)
(insert (concat " " octave-continuation-string))))
@@ -1218,23 +1224,22 @@ q: Don't fix\n" func file))
(defun octave-indent-new-comment-line (&optional soft)
"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."
+unless inside a list. If within a double-quoted string, insert
+`octave-string-continuation-marker' instead. 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) ?')
- (error "Cannot split a single-quoted string"))
- ((eq (octave-in-string-p) ?\")
- (insert octave-continuation-string))
- (t
- (delete-horizontal-space)
- (unless (and (cadr (syntax-ppss))
- (eq (char-after (cadr (syntax-ppss))) ?\())
- (insert " " octave-continuation-string))))
+ (pcase (syntax-ppss)
+ ((app ppss-string-terminator ?\')
+ (user-error "Cannot split a single-quoted string"))
+ ((app ppss-string-terminator ?\")
+ (insert octave-string-continuation-marker))
+ ((pred (not ppss-comment-depth))
+ (delete-horizontal-space)
+ (unless (octave-smie--in-parens-p)
+ (insert " " octave-continuation-string))))
(apply orig args)
(indent-according-to-mode))
@@ -1663,9 +1668,7 @@ code line."
(define-button-type 'octave-help-function
'follow-link t
- 'action (lambda (b)
- (octave-help
- (buffer-substring (button-start b) (button-end b)))))
+ 'action (lambda (b) (octave-help (button-label b))))
(defvar octave-help-mode-map
(let ((map (make-sparse-keymap)))