1

I have got a question about config of emacs startup behavior. I don't have any idea about lisp, I simply love emacs for editing.

What I would like to have is the following:

  1. I call emacs like emacs FILE
  2. emacs opens a window entitled FILE
  3. emacs splits the window horizontally
  4. in the upper frame it opens a file FILE.abc
  5. goes to the bottom frame and it opens FILE.xyz
  6. optimally comes back to the upper frame

I had a look here: how to create a specific window setup on in .emacs and it's half way through. However, the macro thing doesn't really work in my case because I need to pass an argument. Any help greatly appreciated.

Community
  • 1
  • 1
Simon Righley
  • 4,538
  • 6
  • 26
  • 33

1 Answers1

1

In general, you will find yourself better served by Emacs if you stay in it just "visit" (as Emacs has been - for 40 years - calling the operation elsewhere known - for 30 years - as "open") files.

Here is the function (untested):

(defun open-two-files (file)
  "Open FILE.abc in the top window and FILE.xyz in the bottom window.
http://stackoverflow.com/questions/15070481/specifying-emacs-startup-behavior"
  (interactive "FEnter file base name: ")
  (let ((old-window (selected-window))
        (new-window (split-window-below)))
    (find-file (concat file ".abc"))
    (select-window new-window)
    (find-file (concat file ".xyz"))
    (select-window old-window)))

You need to put it into your ~/.emacs.el.

Now, if you have emacs already opened, you need to do M-x open-two-files RET foo RET to open foo.abc and foo.xyz.

If you want to start a new Emacs session, type emacs --eval '(open-two-files "foo")'

sds
  • 58,617
  • 29
  • 161
  • 278
  • You can also, concise comand line syntax by using `command-switch-alist` ( see the example in http://emacswiki.org/emacs/EdiffMode) – Necto Feb 25 '13 at 18:47
  • Hi @sds, thanks for your reply. One problem though. I followed what you said but after the call I'm getting "Symbol's function definition is void: split-window-below" message and nothing happens. Thought this is because the files that I want don't exist so I created them using another editor but this didn't help. Any clue? – Simon Righley Feb 25 '13 at 18:55
  • @SimonRighley: this might be because your Emacs is not as new as mine. What does `C-h k C-x 2` tell you? – sds Feb 25 '13 at 19:16
  • @sds: yeah, that was the thing, I changed split-window-below into split-window-vertically and it works! One more thing. In my .zshrc file i wrote a line that says: emacs(){/usr/bin/emacs --eval '(open-two-files "$1")' -title $1 &}, but I end up with two files that are literally called $1.abc and $1.xyz. Do you happen to know how to "decode" the $ ? – Simon Righley Feb 25 '13 at 19:31
  • @SimonRighley: this is not Emacs magic, but shell: `emacs(){/usr/bin/emacs --eval '(open-two-files "'$1'")' }` - i.e., put single quotes around `$1` to take it out of quoting – sds Feb 25 '13 at 19:55
  • @sds: absolutely fantastic :) i got always confused about different quotation marks ;) Thanks a million man! :) – Simon Righley Feb 25 '13 at 20:03