I want emacs to start with specific settings by default. I found that I need to edit the .emacs file in my home directory and use LISP language. However I do get some errors. I need to have:
Windows split by vertical line (I work in C++ with headers and source files)
Column number mode
Cua-mode enabled (to work with normal copy, cut & paste shortcuts)
That's what I have in my .emacs file:
(column-number-mode)
(load "cua-mode")
(CUA-mode t)
(split-window-right)
I'ver tried coding two middle settings in one - (cua-mode). It didn't work out well.
The column-number-mode works, cua does not load and my window is split horizontally (top and bottom window). Where is my error? Thanks for feedback.
From the comments to the question:
if you're using Emacs 24.1 or later,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-right)
but if you're using an earlier version,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-horizontally)
By the way, the split-window-horizontally also works in later versions of Emacs (I'm using Emacs 25.2.1).
Related
Emacs openfile in terminal don't load configuration correctly. But open file in emacs do load configuration correctly.
I have tried several emacs configuration for cpp:
(eval-after-load "cc-vars" '(lambda() (c-set-style "linux")))
Another one
(add-hook 'c-mode-hook '(lambda() (c-set-style "linux")))
Another one
(eval-after-load "cc-vars" '(setq c-default-style "linux")))
If I type emacs filename they can't be loaded. It seems the emacs always load the default gnu style.
After I type M-x c-mode They can be load correctly. Or I open emacs in terminal and then C-x C-f load the file, those configuration will also be loaded.
Is there any reason for this?
I also tried putting
(c-set-style "linux")
in configuration directly.
They work with emacs filename. But when I open non cpp file there will be an error says can't apply c-set-style on that file.
From the CC-mode manual:
When you create a new buffer, its style will be set from c-default-style.
From the Emacs manual
You can also set the variable c-default-style to specify the default style for various major modes
From the documentation of the c-set-style function:
Set the current buffer to use the style STYLENAME.
This means that any call to c-set-style must ensure that the current buffer is the one you want to set the style for; placing such a call at the toplevel in your init file is then definitely a bad idea.
The simplest fix is just to put (setq c-default-style "linux") at the top level, and then wrap it up in an eval-after-load if you really need one. The variable is intended for this, and hooks should be reserved to control more precisely the style of the current file if you need it (as is suggested by c-default-style documentation).
It seems that for me, (eval-after-load "cc-vars" '(setq c-default-style "linux")) works fine: if I open any file covered by CC-mode, the Linux style is applied. Note that c-mode and CC modes are different things, that there exist the c-mode-hook, c++-mode-hook, c-mode-common-hook and they are all different and will run at different times.
I use sr-speedbar in emacs. On loading, it starts in file mode. I then manually change it to buffers mode. Since I almost always use buffers mode, I would prefer to start it in that. However, I cannot find any way after googling and wondering if someone with Lisp expertise has inputs on how to resolve this
The variable speedbar-initial-expansion-list-name controls the initial view of speedbar. The default value is "files". The other two possibilities are "quick buffers" or "buffers" -- either of the following could be placed in the .emacs file after a (require 'speedbar) statement:
(setq speedbar-initial-expansion-list-name "quick buffers")
or
(setq speedbar-initial-expansion-list-name "buffers")
The sr-speedbar is a package built on speedbar, so you need to consider customizing speedbar itself as well. There is no existing customization option for what you want but you can implement youself by using Hook, in your case, speedbar-mode-hook.
The following should do what you want
(add-hook 'speedbar-mode-hook
(lambda ()
(speedbar-change-initial-expansion-list "quick buffers")))
I copy it from https://stackoverflow.com/a/24291661/2999892 and I've test it by using both speedbar and sr-speedbar.
I am very very new to emacs. I want something like this. Every time I open a new buffer, it should split current winodow vertically. How should I change .emacs file. Please provide some pointers.
You know that you can do this manually with C-x 3 right? So we can use this fact to learn how to add the command to do this to .emacs.
We just need to find out what the function is. So let's do C-h k C-x 3 to find the help for C-x 3. That shows:
C-x 3 runs the command split-window-right, which is an interactive
compiled Lisp function in `window.el'.
So, open .emacs (C-x C-f ~/.emacs), go to the end of the file and add:
(split-window-right)
Then save the file, restart emacs and it should work. I just tested it.
I don't remember the exact route I followed to get this, but I have the following configuration to suggest to Emacs that it should split the frame vertically rather than horizontally when Emacs has the choice (eg when bringing up help).
This seems to work fine on my widescreen monitors.
(setq split-height-threshold nil)
(setq split-width-threshold 160)
Add This to .emacs to split windows vertically as default opening a new buffer in other windows
(setq
split-width-threshold 0
split-height-threshold nil)
From this post on reddit you can set this explicitly for ediff.
(custom-set-variables
'(ediff-window-setup-function 'ediff-setup-windows-plain)
'(ediff-diff-options "-w")
'(ediff-split-window-function 'split-window-horizontally))
This has the advantage that it doesn't impact other splits.
Not being using Emacs all that long (v23, windows) and just discovered M-x ediff. Fantastic.
Although I'm not to keen on the fact it opens its help/navigation in a separate frame/window, meaning that if I lose focus to that window, the single key shortcuts don't work.
For example as soon as I press ? to expand the window, it shifts over top of my current window, so I have to pick up my mouse and move it to another screen. Then if I lose focus to that window and press p / n / j or any other key to work with the diff, it inserts it into my document. So i have to undo, grab mouse, focus to other window, and repeat.
Is there any way to configure these options to show in a split instead?
I didn't know how to do it but it is usually easy to learn with Emacs. First I asked about ediff customizations:
M-x customize-apropos
ediff
I saw there is something called Ediff Window Setup Function which takes the values Multi Frame, Single Frame, or Other Function. Mine was set to Multi Frame and changed it to Single Frame and saved it for future sessions. And Voila! as they say somewhere.
Simply:
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
M-x describe-variable ediff-window-setup-function will enlighten you
further.
For reference my ediff customisation is fairly simple:
(if (locate-library "ediff")
(progn
(autoload 'ediff-files "ediff")
(autoload 'ediff-buffers "ediff")
(eval-after-load "ediff" '(progn
(message "doing ediff customisation")
(setq diff-switches "-u"
ediff-custom-diff-options "-U3"
ediff-split-window-function 'split-window-horizontally
ediff-window-setup-function 'ediff-setup-windows-plain)
(add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
(add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
(add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display)))))
From chapter Window and Frame Configuration in Ediff User's Manual:
The following variable controls how
windows are set up:
ediff-window-setup-function
The multiframe setup is done by the ediff-setup-windows-multiframe
function, which is the default on
windowing displays. The plain setup,
one where all windows are always in
one frame, is done by
ediff-setup-windows-plain, which is
the default on a non-windowing display
(or in an xterm window). In fact,
under Emacs, you can switch freely
between these two setups by executing
the command ediff-toggle-multiframe
using the Minibuffer of the Menubar.
(custom-set-variables
...
'(ediff-window-setup-function (quote ediff-setup-windows-plain))
...)
Not that you would set the variable this way, but it allows you to know these things:
The variable you are interested in is ediff-window-setup-function
The value it needs to be set to is ediff-setup-windows-plain
You can configure the variable from customize: M-x customize-group RET ediff-window
Ediff Window Setup Function: Menu Single Frame
Note: you can avoid using the mouse to go back to the ediff control window by using M-x other-frame. Also found on C-x 5 o.
This no longer works in 2017 gnu emacs (24.5, 25.2, 2017) on windows
(setq ediff-window-setup-function 'ediff-setup-windows-plain) ; stopped working
Even
ediff-toggle-multiframe ; no longer has any effect now.
It works in emacs22.3 on windows, so I have use older emacs from 2008!
When I use Emacs I want to be able to easily display and navigate through a list of files I worked on from not just the current session but from previous sessions. (BTW, running Emacs 22.2 on Windows)
From Joe Grossberg's blog (no longer available):
But if you're using GNU Emacs 21.2
(the latest version, which includes
this as part of the standard distro),
you can just put the following lines
into your .emacs file
;; recentf stuff
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
Then, when you launch emacs, hit
CTRL-X CTRL-R. It will show a list of
the recently-opened files in a buffer.
Move the cursor to a line and press
ENTER. That will open the file in
question, and move it to the top of
your recent-file list.
(Note: Emacs records file names.
Therefore, if you move or rename a
file outside of Emacs, it won't
automatically update the list. You'll
have to open the renamed file with the
normal CTRL-X CTRL-F method.)
Jayakrishnan Varnam has a page
including screenshots of how this
package works.
Note: You don't need the (require 'recentf) line.
Even if you don't have recentf turned on, Emacs is saving a list of files entered via the minibuffer in the variable file-name-history. Also, executing (savehist-mode 1) in your .emacs file makes that variable persist across invocations of Emacs.
So here's a little function that displays the files that actually exist from that list (anyone is welcome to use/build on this):
(defun dir-of-recent-files ()
"See the list of recently entered files in a Dired buffer."
(interactive)
(dired (cons
"*Recent Files*"
(seq-filter
'file-exists-p
(delete-dups
(mapcar (lambda (s) (string-trim-right s "/*"))
file-name-history)
))))
)
I find this quite useful and have it bound to one of those little special function keys on my desktop keyboard. (And so I have not seen the point of turning on recentf...)