branch: master
commit b87f86f462ca17f60763819105945f77b0b2027b
Author: fabacino <[email protected]>
Commit: Oleh Krehel <[email protected]>

    counsel.el: Improve counsel-org-goto functions
    
    * Use org-get-heading instead of org-entry-get to get a headline which
      looks like the one in the buffer (e.g. display of links).
    
    * Add variables counsel-org-goto-display-tags and
      counsel-org-goto-display-todo to control whether tags and todo
      keywords should be displayed.
    
    * Remove 'whole-line from choices of counsel-org-goto-display-style,
      as the same output can be achieved by setting the two new variables
      mentioned above.
    
    Fixes #1008
---
 counsel.el | 91 +++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 49 insertions(+), 42 deletions(-)

diff --git a/counsel.el b/counsel.el
index 6ee6a83..0fc5f1e 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2241,17 +2241,16 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
 
 If headline, the title and the leading stars are displayed.
 
-If whole-line, the whole headline is displayed.  This includes todo keywords
-as well as tags.
-
 If path, the path hierarchy is displayed.  For each entry the title is shown.
 `counsel-org-goto-separator' is used as separator between entries.
 
-If title or any other value, only the title of the headline is displayed."
+If title or any other value, only the title of the headline is displayed.
+
+Use `counsel-org-goto-display-tags' and `counsel-org-goto-display-todo' to
+display tags and todo keywords respectively."
   :type '(choice
           (const :tag "Title only" title)
           (const :tag "Headline" headline)
-          (const :tag "Whole headline" whole-line)
           (const :tag "Path" path))
   :group 'ivy)
 
@@ -2262,6 +2261,16 @@ set to path."
   :type 'string
   :group 'ivy)
 
+(defcustom counsel-org-goto-display-tags nil
+  "If non-nil, display tags in `counsel-org-goto' functions."
+  :type 'boolean
+  :group 'ivy)
+
+(defcustom counsel-org-goto-display-todo nil
+  "If non-nil, display todo keywords in `counsel-org-goto' functions."
+  :type 'boolean
+  :group 'ivy)
+
 (defcustom counsel-org-goto-face-style nil
   "The face used for displaying headlines in `counsel-org-goto' functions.
 
@@ -2269,21 +2278,24 @@ If org, the default faces from `org-mode' are applied, 
i.e. org-level-1
 through org-level-8.  Note that no cycling is in effect, therefore headlines
 on levels 9 and higher will not be styled.
 
-If verbatim, the face used in the buffer is applied.  This is usually the
-same as org except that it depends on how much of the buffer has been
-completely loaded.  If your buffer exceeds a certain size, headlines are
-styled lazily depending on which parts of the tree are visible.  Headlines
-which are not styled yet in the buffer will appear unstyled in the
-minibuffer as well.
-Verbatim is useful if `counsel-org-goto-display-style' is set to whole-line
-and you want tags and todo keywords to be styled properly, otherwise you
-are probably better off using org instead.
+If verbatim, the face used in the buffer is applied.  For simple headlines
+this is usually the same as org except that it depends on how much of the
+buffer has been completely loaded.  If your buffer exceeds a certain size,
+headlines are styled lazily depending on which parts of the tree are visible.
+Headlines which are not styled yet in the buffer will appear unstyled in the
+minibuffer as well.  If your headlines contain parts which are fontified
+differently than the headline itself (eg. todo keywords, tags, links) and you
+want these parts to be styled properly, verbatim is the way to go, otherwise
+you are probably better off using org instead.
 
 If custom, the faces defined in `counsel-org-goto-custom-faces' are applied.
 Note that no cycling is in effect, therefore if there is no face defined
 for a certain level, headlines on that level will not be styled.
 
-If nil or any other value, no face is applied to the headline."
+If nil or any other value, no face is applied to the headline.
+
+See `counsel-org-goto-display-tags' and `counsel-org-goto-display-todo' if
+you want to display tags and todo keywords in your headlines."
   :type '(choice
           (const :tag "Same as org-mode" org)
           (const :tag "Verbatim" verbatim)
@@ -2302,7 +2314,7 @@ to custom."
   :type '(repeat face)
   :group 'ivy)
 
-(declare-function org-entry-get "org")
+(declare-function org-get-heading "org")
 (declare-function org-goto-marker-or-bmk "org")
 (declare-function outline-next-heading "outline")
 
@@ -2313,7 +2325,7 @@ to custom."
   (let ((entries (counsel-org-goto--get-headlines)))
     (ivy-read "Goto: "
               entries
-              :history 'org-goto-history
+              :history 'counsel-org-goto-history
               :action 'counsel-org-goto-action
               :caller 'counsel-org-goto)))
 
@@ -2330,7 +2342,7 @@ to custom."
             (setq entries (counsel-org-goto--get-headlines))))))
     (ivy-read "Goto: "
               entries
-              :history 'org-goto-history
+              :history 'counsel-org-goto-history
               :action 'counsel-org-goto-action
               :caller 'counsel-org-goto-all)))
 
@@ -2347,7 +2359,9 @@ to custom."
           (stack-level 0))
       (goto-char (point-min))
       (while (setq start-pos (outline-next-heading))
-        (let ((name (org-entry-get start-pos "ITEM"))
+        (let ((name (org-get-heading
+                     (not counsel-org-goto-display-tags)
+                     (not counsel-org-goto-display-todo)))
               level)
           (search-forward " ")
           (setq level
@@ -2363,41 +2377,34 @@ to custom."
                  (while (> level stack-level)
                    (push "" stack)
                    (cl-incf stack-level))
-                 (setf (car stack)
-                       (or (and counsel-org-goto-face-style
-                                (counsel-org-goto--add-face name level))
-                           name))
+                 (setf (car stack) (counsel-org-goto--add-face name level))
                  (setq name (mapconcat
                              #'identity
                              (reverse stack)
                              counsel-org-goto-separator)))
-                ((eq counsel-org-goto-display-style 'whole-line)
-                 (setq name (or (and (eq counsel-org-goto-face-style 'verbatim)
-                                     (substring (thing-at-point 'line) 0 -1))
-                                (counsel-org-goto--add-face
-                                 (buffer-substring-no-properties
-                                  start-pos
-                                  (line-end-position))
-                                 level))))
                 (t
                  (when (eq counsel-org-goto-display-style 'headline)
                    (setq name (concat (make-string level ?*) " " name)))
-                 (when counsel-org-goto-face-style
-                   (setq name (counsel-org-goto--add-face name level)))))
+                 (setq name (counsel-org-goto--add-face name level))))
           (push `(,name . ,(point-marker)) entries)))
-      (reverse entries))))
+      (nreverse entries))))
 
 (defun counsel-org-goto--add-face (name level)
   "Add face to headline NAME on LEVEL.
 The face can be customized through `counsel-org-goto-face-style'."
-  (let ((face (or (and (eq counsel-org-goto-face-style 'org)
-                       (concat "org-level-" (number-to-string level)))
-                  (and (eq counsel-org-goto-face-style 'verbatim)
-                       (get-char-property (line-beginning-position) 'face))
-                  (and (eq counsel-org-goto-face-style 'custom)
-                       (nth (1- level) counsel-org-goto-custom-faces)))))
-    (or (and face (propertize name 'face face))
-        name)))
+  (or (and (eq counsel-org-goto-face-style 'org)
+           (propertize
+            name
+            'face
+            (concat "org-level-" (number-to-string level))))
+      (and (eq counsel-org-goto-face-style 'verbatim)
+           name)
+      (and (eq counsel-org-goto-face-style 'custom)
+           (propertize
+            name
+            'face
+            (nth (1- level) counsel-org-goto-custom-faces)))
+      (substring-no-properties name)))
 
 ;;** `counsel-mark-ring'
 (defun counsel--pad (string length)

Reply via email to