1

I want to invoke commands from within MS Office application which have a direct effect on my (open) Emacs application, for example

  • do a search for the currently selected text in Emacs

I wonder how I can do that. Is there a direct way to send commands to Emacs? I'm running Emacs 24.3.1 on Windows 7 with the server options

;;prevent error message of unsafe server (see http://stackoverflow.com/a/1313577/772434 )
(require 'server)
(and (>= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))
(server-start)
;;(add-to-list 'load-path "~/path/to/org/protocol/")
(require 'org-protocol)

and I'm using org-protocol

2

You can send command to Emacs (running in server mode) using emacsclient.

For example :

emacsclient --eval "(org-search-view nil """pattern""")"

If the elisp becomes too complex, you might be better of wrapping it in a file that you can load. For example :

fun.el

(defun my/search (pattern)
  (with-current-buffer "BUFFER-NAME"
     (search-forward pattern)))

command-line

emacsclient --load fun.el --eval '(my/search "PATTERN")'
  • thanks, that works so far. However, the output of the commnand is displayed in the terminal. How can I define the command, so that the command is executed in Emacs itself? I tried with emacsclient --eval (org-search-view "mysearchterm") This should create a list with search results and I'd like to have it displayed in an existing or new Emacs buffer. – MostlyHarmless Jul 31 '14 at 11:39
  • The value that your form evaluates to is displayed in your terminal. However, the elisp forms are executed in Emacs itself. For exemple, org-search-view evaluates to t, which is normally not shown anywhere when you run it interactively, but is displayed in your terminal when you run it using emacsclient. The useful results of your search are however displayed in an Org Agenda buffer, whether you call it interactively from the command loop, or using emacsclient. – Francesco Jul 31 '14 at 12:16
  • 1
    In your case, I think the problem rather comes from the way you call org-search-view non-interactively: the pattern should be the 2nd argument. See my edit and the documentation for org-search-view. – Francesco Jul 31 '14 at 12:16
  • Thanks again for your help and the suggested changes! It still does not work for me - in the command line I get *ERROR*: End of file during parsing and there is no visible change in the open emacs buffers – MostlyHarmless Jul 31 '14 at 12:40
  • 1
    Mmm, it looks like your emacs lisp form is incomplete. Either it is a silly copy/paste problem, or (more probably) a problem with quotes in the command line. Unfortunately, I'm no expert on the Windows command line... – Francesco Jul 31 '14 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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