emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Tim Cross <theophilusx@gmail.com>
Cc: pietru@caramail.com, emacs-orgmode@gnu.org
Subject: Re: Org Capture Menu cannot be fully viewed
Date: Mon, 14 Dec 2020 01:34:01 +0300	[thread overview]
Message-ID: <X9aW2crGRAcCbtQv@protected.rcdrun.com> (raw)
In-Reply-To: <87wnxlig9m.fsf@gmail.com>

* 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



  parent reply	other threads:[~2020-12-13 22:37 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-12 18:02 pietru
2020-12-12 22:09 ` TRS-80
2020-12-12 22:46   ` pietru
2020-12-12 23:13     ` TRS-80
2020-12-12 23:30       ` pietru
2020-12-13  0:00         ` TRS-80
2020-12-13  0:10           ` pietru
2020-12-13 11:06   ` Jean Louis
2020-12-13 18:28     ` pietru
2020-12-13 20:37       ` Jean Louis
2020-12-13 20:52         ` TRS-80
2020-12-13 21:02         ` pietru
2020-12-13 21:48           ` Jean Louis
2020-12-13 22:08             ` pietru
2020-12-13 22:20             ` pietru
2020-12-13 22:00           ` TRS-80
2020-12-13 22:36             ` pietru
2020-12-13 20:32     ` TEC
2020-12-13 21:43       ` Jean Louis
2020-12-13  0:46 ` Tim Cross
2020-12-13  1:32   ` pietru
2020-12-13  2:08     ` pietru
2020-12-13  3:16       ` TRS-80
2020-12-13  3:49         ` pietru
2020-12-13  4:30           ` TRS-80
2020-12-13  9:58             ` pietru
2020-12-13 16:52             ` Jean Louis
2020-12-13 10:24           ` Jean Louis
2020-12-13 18:41             ` pietru
2020-12-13 20:48               ` TRS-80
2020-12-13  4:57         ` pietru
2020-12-13  9:24           ` Christopher Dimech
2020-12-13 23:08           ` TRS-80
2020-12-14  0:04             ` pietru
2020-12-13  9:44       ` Jean Louis
2020-12-13 18:46         ` Christopher Dimech
2020-12-16 18:46         ` No Wayman
2020-12-16 16:58       ` No Wayman
2020-12-13 15:12   ` Jean Louis
2020-12-13 18:08     ` pietru
2020-12-13 20:06     ` Tim Cross
2020-12-13 21:37       ` pietru
2020-12-13 21:57       ` Bastien
2020-12-13 22:31         ` pietru
2020-12-13 23:30         ` Jean Louis
2020-12-13 23:52           ` Bastien
2020-12-13 22:34       ` Jean Louis [this message]
2020-12-14 12:41 ` Marco Wahl
2020-12-14 13:00   ` pietru
2020-12-14 13:18     ` Marco Wahl
2020-12-14 20:02   ` Org Capture Menu cannot be fully viewed - Results of testing C-n, C-p, C-v pietru
2020-12-16 21:46     ` Marco Wahl
2020-12-16 23:25       ` pietru

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=X9aW2crGRAcCbtQv@protected.rcdrun.com \
    --to=bugs@gnu.support \
    --cc=emacs-orgmode@gnu.org \
    --cc=pietru@caramail.com \
    --cc=theophilusx@gmail.com \
    --subject='Re: Org Capture Menu cannot be fully viewed' \
    /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

Code repositories for project(s) associated with this 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).