emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Org Capture Menu cannot be fully viewed


From: Jean Louis
Subject: Re: Org Capture Menu cannot be fully viewed
Date: Mon, 14 Dec 2020 01:34:01 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Tim Cross <theophilusx@gmail.com> [2020-12-13 23:49]:
> > That is very right. I have 1140+ "Sets" which are equivalent to
> > capture templates. Imagine if I would be "defining it" by using Emacs
> > custom, forget it, I would rather break my computer down and switch to
> > paper.
> 
> I have no clue as to why your dragging Emacs custom into this
> discussion. The issue being discussed here is making it easier to
> select from a larger list of capture templates, not defining custom
> templates.

It is double work:

- user already has files which is accessing and using, those are most
  probably files where captured notes need to go

- org agenda already indexed most of files including headings

- org capture defeats its purpose with more then few templates, then
  it could be better sorting it right away in proper file. If that is
  right for user like me

- defining custom templates is double work and left to user, instead
  to computer, to calculate it for user. The more templates there are
  the more hand work user does for computer. It is definitely related
  to the speed and efficiency.

The discussion is brainstorming. It may lead to useful selection
of templates where to store notes. Definition of those templates
allows for many various selections by ID, file+heading,
file+regexp etc. Now any enhancement is rather type of a glue
than well designed solution. It looks to me most logical to use
the key and the description to choose the template, as that is
what each template alreadu has:

(defvar my-capture-template-history nil)

(defun my-capture-choice ()
  (interactive)
  (let* ((collection '())
         (collection (dolist (item org-capture-templates collection)
                       (let* ((key (elt item 0))
                              (description (elt item 1))
                              (headline (car (elt item 3)))
                              (headline (if (string-match "headline"
                                                         (symbol-name headline))
                                            (concat " > " (elt (elt item 3) 2))
                                         ""))
                              (item (concat description " " headline " [" key 
"]")))
                         (push item collection)))))
    (completing-read "Capture to: " collection nil t nil 
'my-capture-template-history)))

That function can already choose one among many templates by
using completion. But it shows collection in some peculiar way
with keys being within [] so that by using completion such as
ivy, user would need to enter: [KEY instead of just key. In
standard completion user would need to enter *[KEY and press TAB
to reach to heading/template by using a key.

Key could be used within [KEY] to find the actual org capture
template programmatically from the selection.

The selection would look like:

Protocol Link > Inbox [L]

Following function must programmatically understand what is the
key L within the selected string: "Protocol Link > Inbox [L]"

(defun string-cut-right-square-bracket-reference (s)
  "Returns the reference within square brackets on the end of S."
  (let* ((space (string-match " " (reverse s))))
    (if space
        (let* ((id (substring (reverse s) 0 space)))
          (if (and (string-match "\\[" id)
                   (string-match "\\]" id))
              (replace-regexp-in-string "\\[\\\|\\]" "" (reverse id))
            nil))
      nil)))

(string-cut-right-square-bracket-reference "Protocol Link > Inbox [L]")
"L"

So it can find the key L from the selection of Org templates.

Then `org-capture' function already allows for the key to be
selected, thus running it as (org-capture nil "L") leads user by
the selected key to the proper template.

Putting it together is this:

(defvar my-capture-template-history nil)

(defun my-capture-choice ()
  (let* ((collection '())
         (collection (dolist (item org-capture-templates collection)
                       (let* ((key (elt item 0))
                              (description (elt item 1))
                              (headline (car (elt item 3)))
                              (headline (if (string-match "headline"
                                                         (symbol-name headline))
                                            (concat " > " (elt (elt item 3) 2))
                                         ""))
                              (item (concat description " " headline " [" key 
"]")))
                         (push item collection)))))
    (completing-read "Capture to: " collection nil t nil 
'my-capture-template-history)))

(defun string-cut-right-square-bracket-reference (s)
  "Returns the reference within square brackets on the end of S."
  (let* ((space (string-match " " (reverse s))))
    (if space
        (let* ((id (substring (reverse s) 0 space)))
          (if (and (string-match "\\[" id)
                   (string-match "\\]" id))
              (replace-regexp-in-string "\\[\\\|\\]" "" (reverse id))
            nil))
      nil)))

(defun my-completing-org-capture ()
  (interactive)
  (let* ((my-capture-choice (my-capture-choice))
         (my-key (string-cut-right-square-bracket-reference my-capture-choice)))
    (when my-key
      (org-capture nil my-key))))

Then user can bind `my-completing-org-capture' to some key to
quickly capture items by using completion. So Pietrum, you can try
using this solution.

Or run M-x my-completing-org-capture

This is not perfect function but I just guess it should work well
for people who have many templates with headlines.

Jean




reply via email to

[Prev in Thread] Current Thread [Next in Thread]