unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#46420: 28.0.50; Wrong line continuation in double-quoted Octave strings
@ 2021-02-10 11:37 Basil L. Contovounesios
  2021-02-11  9:02 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Basil L. Contovounesios @ 2021-02-10 11:37 UTC (permalink / raw)
  To: 46420

[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]

Tags: patch

0. emacs -Q
1. C-x b foo RET
2. M-x octave-mode RET
3. s = "foo C-M-j

This inserts the line continuation marker '...' instead of '\'.

Since Octave 3.8, released over 7 years ago, breaking double-quoted
strings with an ellipsis, or breaking anything else with a backslash, is
deprecated; see https://www.gnu.org/s/octave/NEWS-3.8.html and
(info "(octave) Continuation Lines").

In the Octave 6.1 REPL:

  octave:1> s = "foo...
  warning: '...' continuations in double-quoted character strings are
  obsolete and will not be allowed in a future version of Octave; please
  use '\' instead
  > "
  s = foo
  octave:2> x = [1 \
  warning: using continuation marker \ outside of double quoted strings
  is deprecated and will be removed from a future version of Octave, use
  ... instead
  > ]
  x = 1

I attach a patch which reintroduces the backslash as
octave-string-continuation-marker, alongside the existing ellipsis
octave-continuation-string.

[ I think octave-string-continuation is the perfect name for the
  backslash, but I can imagine it not being very popular ;).
  Naming suggestions welcome. ]

WDYT?

-- 
Basil

In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars)
 of 2021-02-09 built on tia
Repository revision: bff9bd0d3acff0fa0a50e21bdeca024e71fa518b
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: Debian GNU/Linux bullseye/sid

Configured using:
 'configure 'CC=ccache gcc' 'CFLAGS=-O2 -march=native' --config-cache
 --prefix=/home/blc/.local --enable-checking=structs
 --with-x-toolkit=lucid --with-file-notification=yes --with-x'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11
XAW3D XDBE XIM XPM LUCID ZLIB


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-Octave-double-quoted-string-line-continuations.patch --]
[-- Type: text/x-diff, Size: 5546 bytes --]

From 50d5a88ae7bb93efbba1d74af382a3a526134816 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Wed, 10 Feb 2021 01:30:08 +0000
Subject: [PATCH] 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.
(octave-indent-new-comment-line):
* etc/NEWS: Describe new behavior.
---
 doc/misc/octave-mode.texi |  5 +++-
 etc/NEWS                  |  9 +++++++
 lisp/progmodes/octave.el  | 49 +++++++++++++++++++++------------------
 3 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/doc/misc/octave-mode.texi b/doc/misc/octave-mode.texi
index 1adc268969..e330606015 100644
--- a/doc/misc/octave-mode.texi
+++ b/doc/misc/octave-mode.texi
@@ -83,9 +83,12 @@ Using Octave Mode
 @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 bd209de18e..1e447a58d9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2017,6 +2017,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.
+
 \f
 * New Modes and Packages in Emacs 28.1
 
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index ddcc6f5450..a8a86478d8 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -215,9 +215,15 @@ octave-continuation-regexp
   (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 @@ octave-looking-at-kw
     (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 @@ octave-font-lock-texinfo-comment
 (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 @@ 'octave-help-file
 
 (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)))
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#46420: 28.0.50; Wrong line continuation in double-quoted Octave strings
  2021-02-10 11:37 bug#46420: 28.0.50; Wrong line continuation in double-quoted Octave strings Basil L. Contovounesios
@ 2021-02-11  9:02 ` Lars Ingebrigtsen
  2021-02-11 14:45   ` Basil L. Contovounesios
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-11  9:02 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 46420

"Basil L. Contovounesios" <contovob@tcd.ie> writes:

> I attach a patch which reintroduces the backslash as
> octave-string-continuation-marker, alongside the existing ellipsis
> octave-continuation-string.
>
> [ I think octave-string-continuation is the perfect name for the
>   backslash, but I can imagine it not being very popular ;).
>   Naming suggestions welcome. ]
>
> WDYT?

Looks good to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#46420: 28.0.50; Wrong line continuation in double-quoted Octave strings
  2021-02-11  9:02 ` Lars Ingebrigtsen
@ 2021-02-11 14:45   ` Basil L. Contovounesios
  0 siblings, 0 replies; 3+ messages in thread
From: Basil L. Contovounesios @ 2021-02-11 14:45 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46420-done

tags 46420 fixed
close 46420 28.1
quit

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Looks good to me.

Thanks, pushed.

Fix Octave double-quoted string line continuations
21ec45c107 2021-02-11 14:35:47 +0000
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=21ec45c10727403421c41c8c67a752458790afbb

-- 
Basil





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-11 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 11:37 bug#46420: 28.0.50; Wrong line continuation in double-quoted Octave strings Basil L. Contovounesios
2021-02-11  9:02 ` Lars Ingebrigtsen
2021-02-11 14:45   ` Basil L. Contovounesios

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).