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.
This commit is contained in:
parent
0e2b123a4e
commit
21ec45c107
3 changed files with 39 additions and 24 deletions
|
@ -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 ;
|
||||
|
|
9
etc/NEWS
9
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
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Reference in a new issue