3

Is there a way to center the vertical scroll position when using emacs client to open a file at a position?

eg:

emacsclient +$NUM:$COL $FILE --no-wait --alternate-editor=emacs

Is it possible to either:

  • Modify this command so it tells emacs to recenter.
  • Add to a hook that runs (recenter) after has opened a file from a remote request?
1
  • server-switch-hook can help perhaps (untested).
    – NickD
    Apr 14 '17 at 14:55
3

You can always choose the --eval option of emacsclient to perform more complicated tasks:

emacsclient --eval "(progn (find-file \"$FILE\") (goto-line $NUM) (forward-char $COL) (recenter))"
3
  • Can made to work with --alternate-editor=emacs ? - It doesn't open the file or go to the line.
    – ideasman42
    Apr 20 '17 at 5:57
  • @ideasman42 One option would be to remove --alternate-editor=emacs and let emacsclient start emacs --daemon and to connect to that emacs server instance by default. Please see the documentation of emacs-client in this respect. If that does not work for you for any reason you can also write the eval into the --alternate-editor command.
    – Tobias
    Apr 20 '17 at 8:00
  • Re: "you can also write the eval into the --alternate-editor command." - How would this be done? - its already taking part of the --eval, its just using it as a filename instead of evaluating it.
    – ideasman42
    Apr 20 '17 at 9:53

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.