emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Fix M-j with default fill-prefix value
@ 2022-04-20 17:49 Javier Olaechea
  2022-04-22  5:13 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Javier Olaechea @ 2022-04-20 17:49 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 606 bytes --]

org-comment-line-break-function does not handle fill-prefix being set to
nil, which is the default value for fill-prefix. This means that pressing
M-j inside an org-mode buffer in a vanilla installation of Emacs results in
an error. From looking at other callers of
insert-before-markers-and-inherit it is clear that a guard against
fill-prefix being nil is missing.

This has been reported beforehttps://
list.orgmode.org/87o861o9sh.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me/

Cheers,
Javier Olaechea

-- 
"I object to doing things that computers can do." — Olin Shivers

[-- Attachment #1.2: Type: text/html, Size: 902 bytes --]

[-- Attachment #2: 0001-lisp-org.el-Allow-org-c-l-b-f-to-handle-an-empty-fil.patch --]
[-- Type: text/x-patch, Size: 1688 bytes --]

From 372daea6cbee60df03f1a68bd5fabca4212a12c3 Mon Sep 17 00:00:00 2001
From: Javier Olaechea <pirata@gmail.com>
Date: Wed, 20 Apr 2022 11:58:07 -0500
Subject: [PATCH] lisp/org.el: Allow org-c-l-b-f to handle an empty fill-prefix

* org.el (org-comment-line-break-function): When fill-prefix is nil,
don't call `insert-before-markers-and-inherit'.

The default value for fill-prefix is nil,
`insert-before-markers-and-inherit' expects a string. This results in
an error when calling `org-comment-line-break-function', bound to M-j,
on a vanilla installation of Emacs. We should add a guard checking
that fill-prefix is not nill before calling i-b-m-a-i. The only
exception is when adaptive-fill-mode is enabled. This is the approach
that that rest of the code in Emacs takes. Some call-sites listed
below:

* simple.el (default-indent-new-line): uses
  (and fill-prefix (not adaptive-fill-mode) ...)

* newcomment.el (comment-indent-new-line): uses
  (and fill-prefix (not adaptive-fill-mode) ...)

* fill.el (fill-new-line): uses
  (and fill-prefix (not (equal fill-prefix "")) ...)

TINYCHANGE
---
 lisp/org.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2353c6594..4176c683f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19943,7 +19943,8 @@ (defun org-comment-line-break-function (&optional soft)
   (save-excursion (forward-char -1) (delete-horizontal-space))
   (delete-horizontal-space)
   (indent-to-left-margin)
-  (insert-before-markers-and-inherit fill-prefix))
+  (and fill-prefix (not adaptive-fill-mode)
+       (insert-before-markers-and-inherit fill-prefix)))
 
 
 ;;; Fixed Width Areas
-- 
2.29.2.154.g7f7ebe054a


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

* Re: Fix M-j with default fill-prefix value
  2022-04-20 17:49 Fix M-j with default fill-prefix value Javier Olaechea
@ 2022-04-22  5:13 ` Ihor Radchenko
  2022-10-24 13:00   ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2022-04-22  5:13 UTC (permalink / raw)
  To: Javier Olaechea; +Cc: emacs-orgmode

Javier Olaechea <pirata@gmail.com> writes:

> org-comment-line-break-function does not handle fill-prefix being set to
> nil, which is the default value for fill-prefix. This means that pressing
> M-j inside an org-mode buffer in a vanilla installation of Emacs results in
> an error. From looking at other callers of
> insert-before-markers-and-inherit it is clear that a guard against
> fill-prefix being nil is missing.

I guess this is fine to fix the immediate error, but I do not see much
point in the whole org-comment-line-break function. AFAIU, it does not
even recognise whether we are inside comment or not. I just tried to use
the default comment-indent-new-line and it correctly indents paragraphs
and also comments. On the other hand, it does not indent item lists and
src-blocks.

Rather than applying this patch I would remove
org-comment-line-break-function alltogether. It will already be better
than the current state. Alternatively, it should be rewritten to take
into account current element context, similar to org-insert-comment.

Best,
Ihor


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

* Re: Fix M-j with default fill-prefix value
  2022-04-22  5:13 ` Ihor Radchenko
@ 2022-10-24 13:00   ` Ihor Radchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2022-10-24 13:00 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Javier Olaechea, emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> Javier Olaechea <pirata@gmail.com> writes:
>
>> org-comment-line-break-function does not handle fill-prefix being set to
>> nil, which is the default value for fill-prefix. This means that pressing
>> M-j inside an org-mode buffer in a vanilla installation of Emacs results in
>> an error. From looking at other callers of
>> insert-before-markers-and-inherit it is clear that a guard against
>> fill-prefix being nil is missing.
>
> I guess this is fine to fix the immediate error, but I do not see much
> point in the whole org-comment-line-break function. AFAIU, it does not
> even recognise whether we are inside comment or not. I just tried to use
> the default comment-indent-new-line and it correctly indents paragraphs
> and also comments. On the other hand, it does not indent item lists and
> src-blocks.
>
> Rather than applying this patch I would remove
> org-comment-line-break-function alltogether. It will already be better
> than the current state. Alternatively, it should be rewritten to take
> into account current element context, similar to org-insert-comment.

My guess was not correct.
The issue had to be fixed by modifying org-comment-line-break-function
at the end.
Now, fixed on main.
See https://list.orgmode.org/877d1m9343.fsf@localhost/

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2022-10-24 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 17:49 Fix M-j with default fill-prefix value Javier Olaechea
2022-04-22  5:13 ` Ihor Radchenko
2022-10-24 13:00   ` Ihor Radchenko

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).