Skip to content

Instantly share code, notes, and snippets.

@sprig
Last active July 2, 2024 11:32
Show Gist options
  • Save sprig/11499090 to your computer and use it in GitHub Desktop.
Save sprig/11499090 to your computer and use it in GitHub Desktop.
Advice for org-set-tags to disable helm completion
(defun kk/run-with-no-helm (orig-func &rest args)
"Run a function without helm completion."
(if (boundp 'helm-mode)
(let ((orig-helm-mode helm-mode))
(unwind-protect
(progn
(helm-mode 0)
(apply orig-func args)
)
(helm-mode (if orig-helm-mode 1 0))))
(apply orig-func args)
))
(advice-add 'org-icompleting-read :around 'kk/run-with-no-helm)
(advice-add 'org-completing-read :around 'kk/run-with-no-helm)
(advice-add 'org-completing-read-no-i :around 'kk/run-with-no-helm)
(defun kk/org-set-tags-no-helm (orig-func &rest args)
"Run org-set-tags without helm."
(if (boundp 'helm-mode)
(let ((orig-helm-mode helm-mode))
(unwind-protect
(progn
(helm-mode 0)
(apply orig-func args)
)
(helm-mode (if orig-helm-mode 1 0))))
(apply orig-func args)
))
(advice-add 'org-set-tags :around 'kk/org-set-tags-no-helm)
@sprig
Copy link
Author

sprig commented May 4, 2014

org-no-helm.el is a better version that works even for capturing in templates.

Copy link

ghost commented Jul 12, 2015

That was what I was looking for, thank you!

I think I've found a simpler version:
Setting the custom variable helm-completing-read-handlers-alist that tells helm what to use and when.

I placed this in my .emacs and it disabled helm for C-c C-c in an org outline :

(add-to-list 'helm-completing-read-handlers-alist '(org-set-tags))

I don't really know if that is what you looked for, and I hope it helps!

@lckarssen
Copy link

Thanks @sshbio, that was exactly what I needed!

@sprig
Copy link
Author

sprig commented Mar 12, 2016

Thanks @sshbio! It is not exactly what I was after - I had helm enabled everywhere (i.e. it replaced completing-read), and this helped me disable it in a single command, rather than enabling it there. I am pretty sure I didn't know about helm-completing-read-handlers-alist though, so thanks for that as well!

@rekahsoft
Copy link

Worth noting that the way advice is added here is incorrect; otherwise this works :)

Namely, advice should be added like so (notice the missing #):

(advice-add 'org-icompleting-read :around #'kk/run-with-no-helm)

@rekahsoft
Copy link

After spending more time on this, the advise option provided doesn't allow for normal completion when tab is pressed in the quick tag selection menu. I found the solution by here to to preferred.

@sprig
Copy link
Author

sprig commented May 18, 2024

After spending more time on this, the advise option provided doesn't allow for normal completion when tab is pressed in the quick tag selection menu. I found the solution by here to to preferred.

Your comments prompted me to revisit this, as I haven't been using tags too frequently lately, but wanted to start again. Looks like this isn't working correctly anymore with either #' (function-symbol) or with ' (regular symbol). The quoted approach does work except it should be org-set-tags-command. However, at least in my case, I don't get a regular completing-read (i.e. no completions) after excluding it that way.

On the other hand, helm does appear helpful at this time as it allows frictionless addition of a new tag. The only issue is that when skipping the menu with C-u C-u, it adds a comma after the first tag. Replacing the comma with a colon allows one to complete multiple tags, which otherwise get blocked by the comma. A small modification to org.el fixes this for me:

modified   lisp/org.el
@@ -11691,7 +11691,7 @@ in Lisp code use `org-set-tags' instead."
 		      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]*"))
+                         (crm-separator ":"))
 		     (mapconcat #'identity
                                 (completing-read-multiple
 			         "Tags: "

@dwla
Copy link

dwla commented Jul 2, 2024

Thank you so much! This is exactly what I need! I am irritated by the Helm for many times as it pops up when I don't need it in org mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment