4

Is it possible to specify an argument for emacsclient to run a command in the opened file? I would like to set the editor of a program to emacsclient -r '(search-forward-regexp "^<<<")'.

Addition 1

While I can run

emacs file --eval '(search-forward "test")'

the same with emacsclient fails with *ERROR*: Symbol's value as variable is void: file. Very helpful would be an --eval-next so I could define and use a shell alias like

% alias edit-as-shell='emacsclient --eval-next "(shell-mode t)"'
% edit-as-shell ~/bin/script

% alias edit-at-end='emacsclient --eval-next "(end-of-buffer)"'
% edit-at-end file
4
  • I don't understand the question in the current form. do you mean that the program for editing a text file is specified within the text file behind the match for "^<<<"? E.g., the file contains the line <<</usr/bin/vi and you want the file be opened with /usr/bin/vi? (I chose vi here to demonstrate what I mean with something other than emacs.)
    – Tobias
    Apr 28 '17 at 12:36
  • 1
    To run emacs commands on the file fileopened by emacsclient after the file is loaded: emacsclient -s my_server --eval '(progn (find-file "file") (...)(select-frame-set-input-focus (selected-frame)))' May 24 '17 at 7:48
  • @HåkonHægland but this implies that I know the name of the file I'm opening, right? But what if I don't? E.g. I use emacsclient from Qutebrowser when I want to edit some lengthy texts, and the filename Qutebrowser generates is random.
    – Hi-Angel
    Jul 27 '19 at 11:22
  • 1
    Ah, nvm, I figured, Qutebrowser uses {} as a mark in config to show where the filename should be put, so I simply did …(find-file "{}")…, and it worked.
    – Hi-Angel
    Jul 27 '19 at 11:28
2

Something like this:

emacsclient --eval "(with-current-buffer (window-buffer) (search-forward-regexp \"^<<<\"))"
1
  • 1
    Doesn't work for me: emacsclient --eval '(with-current-buffer (window-buffer) (print "hey"))' -c /tmp/1"hey" *ERROR*: Symbol’s value as variable is void: /tmp/1.
    – Hi-Angel
    Jul 27 '19 at 11:13

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