unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace
@ 2017-11-01  5:24 Alex
  2017-11-01 19:36 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alex @ 2017-11-01  5:24 UTC (permalink / raw)
  To: 29098

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

I have 2 small patches that I think should go to emacs-26, and I'm not
sure if they deserve their own individual reports. Is this alright, or
should I split them up in the future?

Anyway, these alleviate/solve some issues that I've seen people report.
The first patch provides more information to an error message, and the
second deals with pressing backspace in a python-mode buffer with an
active region.

When in a python-mode buffer with the contents:

def foo():
    print('bar')

with an active region and point at the "p", then pressing backspace
de-indents the line instead of deleting it. This is at odds with the
behaviour in other modes, where a similar action deletes the line, at
least with ‘delete-active-region’ non-nil.

I thought about making this behaviour conditional using
‘delete-active-region’, but that might be a bit inconsistent.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: error --]
[-- Type: text/x-diff, Size: 1294 bytes --]

From 922fe8f466ad039f65fb423af6636bfd1695f039 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Tue, 31 Oct 2017 21:10:52 -0600
Subject: [PATCH 1/2] Improve error messages regarding initial-buffer-choice

* lisp/startup.el (command-line-1) <initial-buffer-choice>: Make the
messages conform to Emacs conventions, and show the invalid return
value in the message.
---
 lisp/startup.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 4b538d130e..cf88c40e92 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -2506,9 +2506,9 @@ command-line-1
                    ((eq initial-buffer-choice t)
                     (get-buffer-create "*scratch*"))
                    (t
-                    (error "initial-buffer-choice must be a string, a function, or t.")))))
+                    (error "`initial-buffer-choice' must be a string, a function, or t")))))
         (unless (buffer-live-p buf)
-          (error "initial-buffer-choice is not a live buffer."))
+          (error "Value returned by `initial-buffer-choice' is not a live buffer: %S" buf))
         (setq displayable-buffers (cons buf displayable-buffers))))
 
     ;; Display the first two buffers in `displayable-buffers'.  If
-- 
2.14.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: python --]
[-- Type: text/x-diff, Size: 3358 bytes --]

From 50bd5bd058b71031f84c4d5a4d511353c671d66d Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Tue, 31 Oct 2017 22:36:16 -0600
Subject: [PATCH 2/2] Delete active region instead of de-indenting in
 python-mode

This conforms to the behaviour of `backward-delete-char-untabify' when
there's an active region.  183f9296f1 fixes this behaviour for
`delete-selection-mode' only.

* lisp/progmodes/python.el (python-indent-dedent-line): Restructure
and check for an active region conditionally using a new optional
argument.
(python-indent-dedent-line-backspace): Use the new argument to
`python-indent-dedent-line'.
* test/lisp/progmodes/python-tests.el: Add test.
---
 lisp/progmodes/python.el            | 19 +++++++++++--------
 test/lisp/progmodes/python-tests.el | 17 +++++++++++++++++
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 895117b9ee..56faab057d 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1150,21 +1150,24 @@ python-indent-line-function
    (and (memq this-command python-indent-trigger-commands)
         (eq last-command this-command))))
 
-(defun python-indent-dedent-line ()
-  "De-indent current line."
+(defun python-indent-dedent-line (&optional region-inhibits)
+  "De-indent current line.
+If REGION-INHIBITS is non-nil, then don't de-indent when the
+region is active as determined by `use-region-p'."
   (interactive "*")
-  (when (and (not (bolp))
-           (not (python-syntax-comment-or-string-p))
-           (= (current-indentation) (current-column)))
-      (python-indent-line t)
-      t))
+  (unless (or (bolp)
+              (and region-inhibits (use-region-p))
+              (python-syntax-comment-or-string-p)
+              (/= (current-indentation) (current-column)))
+    (python-indent-line t)
+    t))
 
 (defun python-indent-dedent-line-backspace (arg)
   "De-indent current line.
 Argument ARG is passed to `backward-delete-char-untabify' when
 point is not in between the indentation."
   (interactive "*p")
-  (unless (python-indent-dedent-line)
+  (unless (python-indent-dedent-line t)
     (backward-delete-char-untabify arg)))
 
 (put 'python-indent-dedent-line-backspace 'delete-selection 'supersede)
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index a59885637e..1b9cd23d6b 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -2475,6 +2475,23 @@ python-tests-visible-string
                 (line-beginning-position) (line-end-position))
                "abcdef")))))
 
+(ert-deftest python-indent-dedent-line-backspace-4 ()
+  "Check that an active region is deleted instead of the
+line being de-indented."
+  (python-tests-with-temp-buffer
+      "
+def foo():
+    print('bar')"
+    (let ((transient-mark-mode t))
+      (goto-char (point-max))
+      (set-mark (point))
+      (back-to-indentation)
+      (call-interactively #'python-indent-dedent-line-backspace)
+      (should
+       (string= (buffer-substring-no-properties
+                 (line-beginning-position) (line-end-position))
+                "    ")))))
+
 (ert-deftest python-bob-infloop-avoid ()
   "Test that strings at BOB don't confuse syntax analysis.  Bug#24905"
   (python-tests-with-temp-buffer
-- 
2.14.2


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

* bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace
  2017-11-01  5:24 bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace Alex
@ 2017-11-01 19:36 ` Eli Zaretskii
  2017-11-03  8:37 ` Noam Postavsky
  2018-08-09 12:17 ` Noam Postavsky
  2 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2017-11-01 19:36 UTC (permalink / raw)
  To: Alex; +Cc: 29098

> From: Alex <agrambot@gmail.com>
> Date: Tue, 31 Oct 2017 23:24:48 -0600
> 
> I have 2 small patches that I think should go to emacs-26, and I'm not
> sure if they deserve their own individual reports. Is this alright, or
> should I split them up in the future?

If they are unrelated (as in this case, I believe), it is best to
split them.

> >From 922fe8f466ad039f65fb423af6636bfd1695f039 Mon Sep 17 00:00:00 2001
> From: Alexander Gramiak <agrambot@gmail.com>
> Date: Tue, 31 Oct 2017 21:10:52 -0600
> Subject: [PATCH 1/2] Improve error messages regarding initial-buffer-choice
> 
> * lisp/startup.el (command-line-1) <initial-buffer-choice>: Make the
> messages conform to Emacs conventions, and show the invalid return
> value in the message.

This looks okay to me.

> >From 50bd5bd058b71031f84c4d5a4d511353c671d66d Mon Sep 17 00:00:00 2001
> From: Alexander Gramiak <agrambot@gmail.com>
> Date: Tue, 31 Oct 2017 22:36:16 -0600
> Subject: [PATCH 2/2] Delete active region instead of de-indenting in
>  python-mode
> 
> This conforms to the behaviour of `backward-delete-char-untabify' when
> there's an active region.  183f9296f1 fixes this behaviour for
> `delete-selection-mode' only.
> 
> * lisp/progmodes/python.el (python-indent-dedent-line): Restructure
> and check for an active region conditionally using a new optional
> argument.
> (python-indent-dedent-line-backspace): Use the new argument to
> `python-indent-dedent-line'.
> * test/lisp/progmodes/python-tests.el: Add test.

I'll let users of Python mode to comment on this.

Thanks.





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

* bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace
  2017-11-01  5:24 bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace Alex
  2017-11-01 19:36 ` Eli Zaretskii
@ 2017-11-03  8:37 ` Noam Postavsky
  2017-11-28  2:40   ` Noam Postavsky
  2018-08-09 12:17 ` Noam Postavsky
  2 siblings, 1 reply; 5+ messages in thread
From: Noam Postavsky @ 2017-11-03  8:37 UTC (permalink / raw)
  To: Alex; +Cc: 29098

severity 29098 minor
quit

Alex <agrambot@gmail.com> writes:

> I thought about making this behaviour conditional using
> ‘delete-active-region’, but that might be a bit inconsistent.

Could you elaborate on this?  Wouldn't it be more consistent to respect
delete-active-region, like other commands do?  (I assume other commands
do respect it.)





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

* bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace
  2017-11-03  8:37 ` Noam Postavsky
@ 2017-11-28  2:40   ` Noam Postavsky
  0 siblings, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2017-11-28  2:40 UTC (permalink / raw)
  To: Alex; +Cc: 29098

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> Alex <agrambot@gmail.com> writes:
>
>> I thought about making this behaviour conditional using
>> ‘delete-active-region’, but that might be a bit inconsistent.
>
> Could you elaborate on this?  Wouldn't it be more consistent to respect
> delete-active-region, like other commands do?  (I assume other commands
> do respect it.)

Ping?





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

* bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace
  2017-11-01  5:24 bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace Alex
  2017-11-01 19:36 ` Eli Zaretskii
  2017-11-03  8:37 ` Noam Postavsky
@ 2018-08-09 12:17 ` Noam Postavsky
  2 siblings, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2018-08-09 12:17 UTC (permalink / raw)
  To: Alex; +Cc: 29098

retitle 29098 improve initial-buffer-choice error messages
tags 29098 fixed
close 29098 26.2
quit

Alex <agrambot@gmail.com> writes:

> The first patch provides more information to an error message, and the
> second deals with pressing backspace in a python-mode buffer with an
> active region.

I pushed this to emacs-26.

[1: 96be6b6eb9]: 2018-08-09 08:12:07 -0400
  Improve error messages regarding initial-buffer-choice (Bug#29098)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=96be6b6eb99ae1d77702932c97e8b3a147c6265a

> When in a python-mode buffer with the contents:
>
> def foo():
>     print('bar')
>
> with an active region and point at the "p", then pressing backspace
> de-indents the line instead of deleting it. This is at odds with the
> behaviour in other modes, where a similar action deletes the line, at
> least with ‘delete-active-region’ non-nil.

> I thought about making this behaviour conditional using
> ‘delete-active-region’, but that might be a bit inconsistent.

I suggest opening a new bug thread to discuss this.






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

end of thread, other threads:[~2018-08-09 12:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-01  5:24 bug#29098: 26.0.90; [PATCH] 2 patches: initial-buffer-choice and python-indent-dedent-line-backspace Alex
2017-11-01 19:36 ` Eli Zaretskii
2017-11-03  8:37 ` Noam Postavsky
2017-11-28  2:40   ` Noam Postavsky
2018-08-09 12:17 ` Noam Postavsky

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).