emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sebastian Reuße" <seb@wirrsal.net>
To: emacs-orgmode@gnu.org
Cc: "Sebastian Reuße" <seb@wirrsal.net>
Subject: [PATCH 2/2] Guard against empty headings when sorting
Date: Tue, 13 Mar 2018 17:51:45 +0100	[thread overview]
Message-ID: <20180313165145.27160-3-seb@wirrsal.net> (raw)
In-Reply-To: <20180313165145.27160-1-seb@wirrsal.net>

* org.el (org-sort-entries): Guard against empty headings when sorting
alphabetically, numerically.

Due to how ‘org-complex-heading-regexp’ is defined, the title capture group
currently returns nil in empty headings, which we don’t want to pass on to
‘org-sort-remove-invisible’.
---
 lisp/org.el | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 76bc60c88..07203c9e1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8756,15 +8756,17 @@ (defun org-sort-entries
 	  (lambda ()
 	    (cond
 	     ((= dcst ?n)
-	      (if (looking-at org-complex-heading-regexp)
-		  (string-to-number
-		   (org-sort-remove-invisible (match-string 4)))
-		nil))
+	      (let ((heading (and (looking-at org-complex-heading-regexp)
+				  (match-string 4))))
+		(if heading
+		    (string-to-number (org-sort-remove-invisible heading))
+		  0)))
 	     ((= dcst ?a)
-	      (if (looking-at org-complex-heading-regexp)
-		  (funcall case-func
-			   (org-sort-remove-invisible (match-string 4)))
-		nil))
+	      (let ((heading (and (looking-at org-complex-heading-regexp)
+				  (match-string 4))))
+		(if heading
+		    (funcall case-func (org-sort-remove-invisible heading))
+		  "")))
 	     ((= dcst ?k)
 	      (or (get-text-property (point) :org-clock-minutes) 0))
 	     ((= dcst ?t)
-- 
2.16.2

  parent reply	other threads:[~2018-03-13 16:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 16:51 [BUG] org-sort-entries errors out when headline is empty Sebastian Reuße
2018-03-13 16:51 ` [PATCH 1/2] Extend org-sort-entries test Sebastian Reuße
2018-03-13 16:51 ` Sebastian Reuße [this message]
2018-03-20  8:53 ` [BUG] org-sort-entries errors out when headline is empty Nicolas Goaziou
2018-03-23 10:43   ` Sebastian Reuße
2018-04-20  9:30     ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180313165145.27160-3-seb@wirrsal.net \
    --to=seb@wirrsal.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).