-
-
Notifications
You must be signed in to change notification settings - Fork 339
counsel.el: increase org-goto/org-agenda-headlines UI consistency #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* counsel.el (counsel-org-goto): obey new ‘counsel-org-goto-display-priority’ (counsel-org-agenda-headlines): obey ‘counsel-org-goto-foo’ variables (except for ‘…-face-style’, ‘…-custom-faces’)
Thanks. I don't see your email on the |
It should be in there, I have an assignment (#1027005). I’m not sure which e-mail address I used though. |
counsel.el
Outdated
@@ -2669,7 +2669,8 @@ otherwise continue prompting for tags." | |||
(fset 'org-set-tags store)))) | |||
|
|||
(defcustom counsel-org-goto-display-style 'path | |||
"The style for displaying headlines in `counsel-org-goto' functions. | |||
"The style for displaying headlines in `counsel-org-goto' and \ | |||
`counsel-org-agenda-headlines' functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the conventions outlined in (elisp) Documentation Tips
, in particular keeping the first line of docstrings brief and to the point, e.g.
"The style for displaying Org headlines.
This is used by functions `counsel-org-goto' and
`counsel-org-agenda-headlines'.
or similar. The basic idea is not to list call sites in the variable's summary. The same applies to the other docstrings in this patch.
counsel.el
Outdated
?*)) | ||
(todo (nth 2 components)) | ||
(priority (nth 3 components)) | ||
(level (when (eq counsel-org-goto-display-style 'headline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we care about the expression's value, it's more correct to use and
in place of when
here and in all corresponding cases below.
counsel.el
Outdated
(make-string | ||
(if org-odd-levels-only | ||
(nth 1 components) | ||
(nth 0 components)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write this as (nth (if org-odd-levels-only 1 0) components)
, but maybe that's just me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were just reindented. I prefer to hold back on refactoring for a separate commit.
counsel.el
Outdated
@@ -4107,7 +4123,10 @@ candidate." | |||
level | |||
todo | |||
(if priority (format "[#%c]" priority)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re: preferring and
over conditionals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not replace the surrounding (cl-remove-if 'null ...)
with (delq nil ...)
while we're at it?
counsel.el
Outdated
(if path (mapconcat 'identity | ||
(append path (list text)) | ||
counsel-org-goto-separator) | ||
text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if path
(mapconcat #'identity
(append path (list text))
counsel-org-goto-separator)
text)
is the same as
(mapconcat #'identity
(append path (list text))
counsel-org-goto-separator))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
counsel.el
Outdated
@@ -2796,7 +2805,8 @@ to custom." | |||
(while start-pos | |||
(let ((name (org-get-heading | |||
(not counsel-org-goto-display-tags) | |||
(not counsel-org-goto-display-todo))) | |||
(not counsel-org-goto-display-todo) | |||
(not counsel-org-goto-display-priority))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org-get-heading
only accepts two optional arguments in Org versions < 9.1.1, which was only released a couple of months ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you opt for leaving it out rather, or do a version comparison?
I’m pushing some fix-ups with sloppier commit messages to be squashed if desired. |
If we were nit-picky, generalizing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I find the when
variants preferable. People seem to be somewhat divided on this. In line with other languages, I don’t see when
as a signal that the return value is discarded. Rather, I tend to read and
as a signal that only the truthiness of the return value matters. But if this style is used in the remainder of counsel it’s probably best to apply it.
I don't see a reason to leave it out, though feature detection is usually better than version comparison, especially with a package as unstable as Org. Unfortunately the function From dfa538f86beb56078df32cd904e139b52062ec45 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 28 Nov 2017 17:18:11 +0000
Subject: [PATCH] counsel.el: Fix org-get-heading invocation
(counsel--org-get-heading-args): New defun.
(counsel-org-goto--get-headlines): Use it.
Hoist argument calculation out of loop.
---
counsel.el | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/counsel.el b/counsel.el
index 8bafff3..f51b022 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2802,21 +2802,33 @@ counsel-org-goto-action
"Go to headline in candidate X."
(org-goto-marker-or-bmk (cdr x)))
+(defun counsel--org-get-heading-args ()
+ "Return list of arguments for `org-get-heading'.
+Try to return the right number of arguments for the current Org
+version. Argument values are based on the
+`counsel-org-headline-display-*' user options."
+ (nbutlast (mapcar #'not (list counsel-org-headline-display-tags
+ counsel-org-headline-display-todo
+ counsel-org-headline-display-priority))
+ (if (if (fboundp 'func-arity)
+ (< (cdr (func-arity #'org-get-heading)) 3)
+ (version< org-version "9.1.1"))
+ 1 0)))
+
(defun counsel-org-goto--get-headlines ()
"Get all headlines from the current org buffer."
(save-excursion
(let (entries
start-pos
stack
- (stack-level 0))
+ (stack-level 0)
+ (heading-args (counsel--org-get-heading-args)))
(goto-char (point-min))
(setq start-pos (or (and (org-at-heading-p)
(point))
(outline-next-heading)))
(while start-pos
- (let ((name (org-get-heading
- (not counsel-org-headline-display-tags)
- (not counsel-org-headline-display-todo)))
+ (let ((name (apply #'org-get-heading heading-args))
level)
(search-forward " ")
(setq level
--
2.15.0 Alternatively, we could go with a more Pythonic approach, such as From d87557d9a020c5d9b1503faa3e94e65a42976872 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 28 Nov 2017 17:35:28 +0000
Subject: [PATCH] counsel.el: Fix org-get-heading invocation
(counsel-org-goto--get-headlines): Handle differing arity of
org-get-heading across Org versions. Hoist argument calculation out
of loop.
---
counsel.el | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/counsel.el b/counsel.el
index 8bafff3..4f0080a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2808,15 +2808,19 @@ counsel-org-goto--get-headlines
(let (entries
start-pos
stack
- (stack-level 0))
+ (stack-level 0)
+ (args (mapcar #'not (list counsel-org-headline-display-tags
+ counsel-org-headline-display-todo
+ counsel-org-headline-display-priority))))
(goto-char (point-min))
(setq start-pos (or (and (org-at-heading-p)
(point))
(outline-next-heading)))
(while start-pos
- (let ((name (org-get-heading
- (not counsel-org-headline-display-tags)
- (not counsel-org-headline-display-todo)))
+ (let ((name (condition-case nil
+ (apply #'org-get-heading args)
+ (wrong-number-of-arguments
+ (apply #'org-get-heading (nbutlast args)))))
level)
(search-forward " ")
(setq level
--
2.15.0 This is more reliable than both Either way I think this is an opportunity to hoist the argument calculation out of the loop.
Sure, I wasn't suggesting a Tour-de-France commit; but I think it's perfectly acceptable for the same PR to include multiple relevant commits. Even if you don't like my
I don't mind this, but it's @abo-abo 's call. I prefer
Obviously there exist multiple opinions and tastes on this and many other coding styles, and mine carry little to no weight here. Nevertheless, there is no arguing that In this particular case, we are evaluating simple logical conditional expressions that can easily be expressed in terms of |
I can't check by assignment number, only by name and/or email. I can't find neither. There's only one possibility with the surname spelled differently (Rose). |
(counsel--org-get-heading-args): New defun. (counsel-org-goto--get-headlines): Use it. Hoist argument calculation out of loop.
The copyright clerk was so kind to take care of the copyright.list entry. In the meantime I pushed Basil’s patch for the version guard logic. |
Thanks. I see one entry that could be it, with email: mail at reusse dot net. It's your name, but the surname has "n" added to the end. Is that you? In any case, I would prefer if the email addresses on the commit message and on the list coincided. You can change either one, whichever you prefer. |
Thanks for checking. I’ll contact FSF again to see if they would update the e-mail address, and possibly get rid of that name typo. |
Also followed @basil-conto’s suggestion to use |
So, hopefully, copyright.list should now list both e-mail addresses and the correct name. |
@eigengrau Good thing you didn't follow my Pythonic version guard suggestion as I just noticed it suffers from a significant bug by using |
@basil-conto, because |
@eigengrau Sorry about the noise, I was actually right the first time. It works, but in an error-prone way, which only further supports my preference for the approach you went with. :) |
It's funny, your surname now has an extra |
(counsel--org-get-heading-args): New defun. (counsel-org-goto--get-headlines): Use it. Hoist argument calculation out of loop. Fixes #1324
Thanks, all. |
Cheers! 👍 |
(counsel-org-agenda-headlines): obey ‘counsel-org-goto-foo’ variables (except
for ‘…-face-style’, ‘…-custom-faces’)