emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Heinrich <com-orgmode-mailinglist@gladbachcity.de>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-capture and fast selection of tags
Date: Sat, 16 Jul 2022 17:03:00 +0200	[thread overview]
Message-ID: <e5fe96a6ebfbd47fb55bc9969cf729ed49557953.camel@gladbachcity.de> (raw)
In-Reply-To: <87a699e7zk.fsf@localhost>


[-- Attachment #1.1: Type: text/plain, Size: 1841 bytes --]

Hi Ihor,

thanks for your feedback. I attached a patch, but I'm not sure why you said "all but the last line".
That last line for me was (org-set-tags tags), which proved important as otherwise the tags were not
set in the buffer.

Anyways, please find the patch attached. Feedback is welcome, particularly on naming the auxiliary
function (org-input-tags does not seem like a great name).

I didn't sign any papers yet, but as this is just a minor refactoring without new logic, I'm not
sure whether it would be required.

Best
Christian

On Sat, 2022-07-16 at 17:12 +0800, Ihor Radchenko wrote:
> Christian Heinrich <com-orgmode-mailinglist@gladbachcity.de> writes:
> 
> > I looked at the code and came up with a patch that works for me (see below). However, this may
> > change behavior for others:
> 
> Thanks!
> 
> > 1. The original %^g will work on non-headlines, but if (org-set-tags-command) is called as I do,
> > this is no longer possible and would need to be checked (what would be a good way here?)
> > 
> > 2. Can I really deduce from (org-use-fast-tag-selection) being non-nil that fast selection
> > should be
> > used in capture templates as well? Does it actually make sense to incorporate this into %^g/G?
> > 
> > I am neither a lisp programmer nor acquainted with the org codebase; this is a draft I came up
> > with. If you can provide me with further feedback, I'm willing to make this more stable.
> 
> The idea is reasonable, but using org-set-tags-command is not ideal
> indeed. Instead, you can take the relevant part of org-set-tags-command
> (it is all but last line of the "t" cond clause) and put it into a
> separate auxiliary function. Then, you can simply call that function
> inside the org-set-tags-command and inside the capture template code.
> 
> Best,
> Ihor

[-- Attachment #1.2: org-capture-add-fast-tag-select-support.diff --]
[-- Type: text/x-patch, Size: 5311 bytes --]

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 9ef160d16..4f7652ca3 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -72,6 +72,7 @@
 (defvar crm-separator)
 (defvar org-end-time-was-given)
 (defvar org-keyword-properties)
+(defvar org-use-fast-tag-selection)
 (defvar org-remember-default-headline)
 (defvar org-remember-templates)
 (defvar org-store-link-plist)
@@ -1751,21 +1752,8 @@ Expansion occurs in a temporary Org mode buffer."
 			     (org-global-tags-completion-table
 			      (cond ((equal key "G") (org-agenda-files))
 				    (file (list file))
-				    (t nil))))
-			    (org-add-colon-after-tag-completion t)
-			    (ins (mapconcat
-				  #'identity
-				  (let ((crm-separator "[ \t]*:[ \t]*"))
-                                    (completing-read-multiple
-				     (if prompt (concat prompt ": ") "Tags: ")
-				     org-last-tags-completion-table nil nil nil
-				     'org-tags-history))
-				  ":")))
-		       (when (org-string-nw-p ins)
-			 (unless (eq (char-before) ?:) (insert ":"))
-			 (insert ins)
-			 (unless (eq (char-after) ?:) (insert ":"))
-			 (when (org-at-heading-p) (org-align-tags)))))
+				    (t nil)))))
+               (org-input-tags)))
 		    ((or "C" "L")
 		     (let ((insert-fun (if (equal key "C") #'insert
 					 (lambda (s) (org-insert-link 0 s)))))
diff --git a/lisp/org.el b/lisp/org.el
index dd33028c6..6631d2a0a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11445,49 +11445,53 @@ in Lisp code use `org-set-tags' instead."
 	   'region)
 	 (lambda () (when (org-invisible-p) (org-end-of-subtree nil t))))))
      (t
-      (save-excursion
-	(org-back-to-heading)
-	(let* ((all-tags (org-get-tags))
-	       (table (setq org-last-tags-completion-table
-			    (org--tag-add-to-alist
-			     (and org-complete-tags-always-offer-all-agenda-tags
-				  (org-global-tags-completion-table
-				   (org-agenda-files)))
-			     (or org-current-tag-alist (org-get-buffer-tags)))))
-	       (current-tags
-		(cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag))
-			      all-tags))
-	       (inherited-tags
-		(cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag))
-				  all-tags))
-	       (tags
-		(replace-regexp-in-string
-		 ;; Ignore all forbidden characters in tags.
-		 "[^[:alnum:]_@#%]+" ":"
-		 (if (or (eq t org-use-fast-tag-selection)
-			 (and org-use-fast-tag-selection
-			      (delq nil (mapcar #'cdr table))))
-		     (org-fast-tag-selection
-		      current-tags
-		      inherited-tags
-		      table
-		      (and org-fast-tag-selection-include-todo org-todo-key-alist))
-		   (let ((org-add-colon-after-tag-completion (< 1 (length table)))
-                         (crm-separator "[ \t]*:[ \t]*"))
-		     (mapconcat #'identity
-                                (completing-read-multiple
-			         "Tags: "
-			         org-last-tags-completion-table
-			         nil nil (org-make-tag-string current-tags)
-			         'org-tags-history)
-                                ":"))))))
-	  (org-set-tags tags)))))
+      (org-input-tags)))
     ;; `save-excursion' may not replace the point at the right
     ;; position.
     (when (and (save-excursion (skip-chars-backward "*") (bolp))
 	       (looking-at-p " "))
       (forward-char))))
 
+(defun org-input-tags ()
+  "Test"
+  (save-excursion
+    (org-back-to-heading)
+    (let* ((all-tags (org-get-tags))
+           (table (setq org-last-tags-completion-table
+                        (org--tag-add-to-alist
+                          (and org-complete-tags-always-offer-all-agenda-tags
+                               (org-global-tags-completion-table
+                                 (org-agenda-files)))
+                          (or org-current-tag-alist (org-get-buffer-tags)))))
+           (current-tags
+             (cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag))
+                           all-tags))
+           (inherited-tags
+             (cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag))
+                               all-tags))
+           (tags
+             (replace-regexp-in-string
+               ;; Ignore all forbidden characters in tags.
+               "[^[:alnum:]_@#%]+" ":"
+               (if (or (eq t org-use-fast-tag-selection)
+                       (and org-use-fast-tag-selection
+                            (delq nil (mapcar #'cdr table))))
+                 (org-fast-tag-selection
+                   current-tags
+                   inherited-tags
+                   table
+                   (and org-fast-tag-selection-include-todo org-todo-key-alist))
+                 (let ((org-add-colon-after-tag-completion (< 1 (length table)))
+                       (crm-separator "[ \t]*:[ \t]*"))
+                   (mapconcat #'identity
+                              (completing-read-multiple
+                                "Tags: "
+                                org-last-tags-completion-table
+                                nil nil (org-make-tag-string current-tags)
+                                'org-tags-history)
+                              ":"))))))
+      (org-set-tags tags))))
+
 (defun org-align-tags (&optional all)
   "Align tags in current entry.
 When optional argument ALL is non-nil, align all tags in the

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-07-16 15:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26  9:32 org-capture and fast selection of tags Christian Heinrich
2022-07-11  2:02 ` Ihor Radchenko
2022-07-14 10:12   ` Christian Heinrich
2022-07-16  9:12     ` Ihor Radchenko
2022-07-16 15:03       ` Christian Heinrich [this message]
2022-07-17 10:14         ` Ihor Radchenko
2022-08-23  2:17           ` Ihor Radchenko
2022-09-28 18:40             ` Christian Heinrich
2022-09-29  3:57               ` Ihor Radchenko
2023-04-02 10:21                 ` Ihor Radchenko

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=e5fe96a6ebfbd47fb55bc9969cf729ed49557953.camel@gladbachcity.de \
    --to=com-orgmode-mailinglist@gladbachcity.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /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).