how to create a specific window setup on in .emacs

大城市里の小女人 提交于 2019-12-11 00:46:10

问题


I am very new with emacs and Lisp, though from experience with other functional languages it's not too hard for me to mimic what I am seeing in useful code snippets. I've added some nice window toggling features in the .emacs file and they are working well.

But on start-up, I'd like to configure a specific arrangement of windows/frames. Basically, I want to do the following each time I launch emacs (which is generally at most once per day and then it is left open for days/weeks).

1. Split the screen in half (C-x 2)
2. Grow the top half bigger by 20 lines (C-u 20 C-x ^)
3. Open a second frame of emacs (C-x 5 2)

Ideally, I'd even like to maximize the first frame on my left monitor and the second frame on my right monitor, but I can do without that.

I am just wondering how you write the function equivalent of the key commands into the .emacs file.


回答1:


The best feature in Emacs is the self documenting help, so you can easily figure out how to write the desired command in Emacs-lisp with experience in other languages.

But because what you want is a straight forward sqeuence of keys, a macro would serve you best, and it gives you a good place to start writing

Here is a keysequence I entered:

 C-x (  C-x 2 C-u 2 0 C-x ^ C-x 5 2 <switch-frame> C-x ) 

I've recorded a macro to do what you asked. Then M-x edit-last-kbd-macro, I see:

;; Keyboard Macro Editor.  Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: C-x 2 C-u 20 C-x ^ C-x 5 2

Command: last-kbd-macro
Key: none

Macro:


C-x 2           ;; split-window-below
C-u 20 C-x ^        ;; enlarge-window
C-x 5 2         ;; make-frame-command

Then M-x name-last-kbd-macro "foo" M-x insert-kbd-macro "foo"

(fset 'foo
   [?\C-x ?2 ?\C-u ?2 ?0 ?\C-x ?^ ?\C-x ?5 ?2 (switch-frame #<frame  *Minibuf-1* 0x101855410>)])

Add the last chunk to your .emacs file, and call it with

(foo)



回答2:


As a follow-up to event_jr's answer, it's interesting to note that the return value of (kbd) can be evaluated directly as a keyboard macro. This can be assigned to a key as an alternative to defining a regular keyboard macro, but in your case -- a one-off sequence you wish to place in your .emacs file, in which efficiency is not a concern -- you might find it nicer to write out the key sequence in the friendly kbd format (and with comments, because kbd deals with those) instead of the output of insert-kbd-macro, which is much harder to comprehend without invoking the macro editor.

(execute-kbd-macro (kbd "
 C-x 2           ;; split-window-below
 C-u 20 C-x ^    ;; enlarge-window
 C-x 5 2         ;; make-frame-command
"))

Here I've just copied and pasted the output from the keyboard macro editor as shown by event_jr, so note that you can use that facility to auto-generate the comments :)

That said, personally I would encourage you to write such things as real function calls:

(split-window-below)
(enlarge-window 20)
(make-frame-command)



回答3:


There is a more 'baked-in' way of configuring frame and window configurations. There are three relevant functions:

C-x r f         frame-configuration-to-register
C-x r w         window-configuration-to-register
C-x r j         jump-to-register

Jumping to a register which contains a frame / window configuration will load that frame / window configuration.

A window configuration is not per frame, it (appears to) apply to all frames. I've not tested frame configurations, because they appear not to work under xmonad.

However, I've no idea how you'd actually save them between sessions, so this is more of an FYI than anything else.



来源:https://stackoverflow.com/questions/12512471/how-to-create-a-specific-window-setup-on-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!