DrTang
DrTang

Reputation: 3

How to auto execute commands after opening a file in GNU Emacs

How to do something like this: auto execute commands (split-window-right) (follow-mode) (visual-line-mode) after opening a file.

Upvotes: 0

Views: 452

Answers (1)

Lindydancer
Lindydancer

Reputation: 26094

One way to do it is to write your own "open file" command:

(defun my-find-file ()
  "Like `find-file', but splits screen and enables Follow Mode."
  (interactive)
  (call-interactively #'find-file)
  (follow-delete-other-windows-and-split)
  (visual-line-mode 1))

You can bind it to C-x C-f:

(global-set-key (kbd "C-x C-f") #'my-find-file)

I've used follow-delete-other-windows-and-split rather than split-window-right and follow-mode and the latter doesn't work that well when a frame already contains multiple windows.

Also, you might consider enabling visual-line-mode using other mechanisms like mode-specific hooks or global-visual-line-mode.

Upvotes: 2

Related Questions