jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
280 stars 60 forks source link

notmuch company support in org-msg-edit-mode #53

Closed runekaagaard closed 3 years ago

runekaagaard commented 4 years ago

Hi

Related to GH-49. If you patch notmuch-company.el v0.29.1 with this diff:

70c75
<       (prefix (and (derived-mode-p 'message-mode)
---
>       (prefix (and (or (derived-mode-p 'message-mode) (eq major-mode 'org-msg-edit-mode))

Then it's possible to autocomplete email addresses in the To: line when you have this in your init.el:

(require 'notmuch-company)
(add-hook 'org-msg-edit-mode-hook 'notmuch-company-setup)

I'm pretty bad at elisp, what would be the best way to implement this feature?

Best, Rune

obar commented 4 years ago

I think it should go into notmuch-company as that's where the restriction happens. The code you wrote seems fine for a contribution to that package. As it stands, org-msg and notmuch are working happily together on my system with #49 and there isn't an interference with notmuch address completion.

runekaagaard commented 4 years ago

Guess you are right. I'm on outlook, not google so your solution at #49 does not apply to me.

obar commented 4 years ago

I should say that my comment in the other thread is just for an address source, and there are other options for notmuch. Have you looked through notmuch-address.el? Perhaps you'll find useful avenues to explore there.

arvindsv commented 4 years ago

@runekaagaard This is really hacky but I use this to get past this issue:

(defun arvindsv/org-msg-notmuch-company (old-fn &rest args)
  ;; Cheat and say that this buffer, which should be org-msg-edit-mode, is derived from message-mode.
  (cl-letf (((symbol-function 'derived-mode-p) (lambda (mode) (if (eq mode 'message-mode) t (derived-mode-p mode)))))
    (apply old-fn args)))

(advice-add 'notmuch-company :around #'arvindsv/org-msg-notmuch-company)
runekaagaard commented 4 years ago

@arvindsv Heh, Thats great, thx!!

joshuaoco commented 3 years ago

@runekaagaard This is really hacky but I use this to get past this issue:

(defun arvindsv/org-msg-notmuch-company (old-fn &rest args)
  ;; Cheat and say that this buffer, which should be org-msg-edit-mode, is derived from message-mode.
  (cl-letf (((symbol-function 'derived-mode-p) (lambda (mode) (if (eq mode 'message-mode) t (derived-mode-p mode)))))
    (apply old-fn args)))

(advice-add 'notmuch-company :around #'arvindsv/org-msg-notmuch-company)

With this, I'm getting Company: backend company-capf error "Lisp nesting exceeds ‘max-lisp-eval-depth’" with args (prefix)

Any ideas why that would be?

And perhaps a slightly less hacky version (which has the same issue as above) is to add org-msg-edit-mode to the derived-mode list.

(put 'org-msg-edit-mode 'derived-mode-parent 'message-mode)

But, having said that, it doesn't work :)

HyunggyuJang commented 3 years ago

@Joshuao95, I suspect that you might have not set notmuch-company as a backend for org-msg-edit-mode, not the notmuch-message-mode, which the the default one. After setting it properly, and with your suggested tweak, I achieved posed desirable behavior. Maybe it is worth to try.

joshuaoco commented 3 years ago

@HyunggyuJang Perfect, thanks a lot, that solves it for me too

HyunggyuJang commented 3 years ago

@Joshuao95 ;)

obar commented 3 years ago

This is now patched in notmuch and it'll be in the next release, thanks @runekaagaard! This issue can be closed.

runekaagaard commented 3 years ago

Beautiful!