0

I am using a cool software called Emacs Anywhere.

Usually, I invoke this software to write on Stack Overflow and on GitHub. Both websites use markdown.

Hence, almost every time I invoke Emacs Anywhere, I need to manually enable markdown mode.

I have markdown-mode with this package installed in my init file:

;; This package brings keybindings similar to org-mode, but to
;; markdown format!
(use-package markdown-mode
  :ensure t
  :mode ("README\\.md\\'" . gfm-mode)
  :init (setq markdown-command "multimarkdown"))

I would like to make things more automatic. Take into account that for Emacs Anywhere to work it is necessary to have an Emacs server going on. This is provided by my config file, with:

;; Start server so that I can easily launch succesfully the
;; application called Emacs Anywhere
(add-hook 'after-init-hook #'server-start)

Also, every time Emacs Anywhere is invoked, Emacs creates a new frame. Moreover, there is an addition of a new buffer called Emacs Anywhere.

Finally, what triggers the invocation of Emacs Anywhere is not exactly Emacs, but a shortcut defined on System Preference of the macOS.

Hence, I would like to ask, what is the best approach to automate the process of enabling markdown-mode? How to do it?

1 - Creating a hook enabling markdown triggered by frame creation in general?

Obs.: Maybe I am missing something, but I believe I only use Emacs new frames after invoking Emacs anywhere. It does not seem to be useful in my day-to-day activies programming, on Magit, dired, org-mode files...

2 - Creating a hook based on some inner workings of the Emacs server? For instance, a hook catching the connection between Emacs Anywhere and the frame creation?

3 - Maybe a hook triggered by the creation of buffer name written as *Emacs Anywhere*?

4 - Another approach?

2
  • 1
    markdown-mode doesn't seem to be included in vanilla Emacs. Please add some info about it to your question. It's impossible to know from your question what it is or does - minor mode? global/local? major mode?
    – Drew
    Commented Aug 28, 2022 at 23:48
  • Thank you trying to help, @Drew. Indeed the question was missing information. I have just updated it. Commented Aug 29, 2022 at 1:25

2 Answers 2

2

Inspection of the github page you linked to shows that Emacs Anywhere already provides hooks for this purpose and examples of their use. Look here: https://github.com/zachcurry/emacs-anywhere#hooks.

0

Based on @FranBurstall, I looked at the documentation, and then I wrote the following:

;; Define a function to enable markdown-mode after Emacs Anywhere is invoked
(defun pmd/markdown-mode-emacs-anywhere (app-name window-title x y w h)
  (markdown-mode))

;; Hook your function
(add-hook 'ea-popup-hook 'pmd/markdown-mode-emacs-anywhere)

Not sure if this is the most elegant way to do it... But it works! :)

I tried removing all parameters. But it broke the function. So I am leaving it with all this unused parameters.

2
  • 1
    It sounds like you should accept Fran's answer as that did in fact solve your problem.
    – glucas
    Commented Aug 29, 2022 at 16:41
  • ok, I forgot to do it. Thanks Commented Aug 29, 2022 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.