emacs - startup window size changed from default to maximum - emacs

I use below code to setup emacs using fullscreen:
(setq initial-frame-alist '( (fullscreen . maximized)))
(setq default-frame-alist '( (fullscreen . fullheight)))
I wish it startup with maximized window, the behavior is almost as expected but the window size firstly with default size, then I can see it changed to maximum size obviously.
How can emacs startup to fullscreen in one step?

Look at the documentation for initial-frame-alist (C-h v initial-frame-alist). In particular, Emacs creates the first frame before reading init.el, so you need to specify these things somewhere other than init.el. Two common ways are to give the --maximized command line option, or to set the X11 resource Emacs.Fullscreen: maximized; either of these are applied before init.el is read and evaluated.
It looks like you're on OS X, which I don't have, and it may be different there.
Update for Emacs 27:
You can set these things in early-init.el, which loads before the GUI starts.

Related

start emacs sr-speedbar in buffers mode on loading

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.

Function defined in .emacs does not start automatically

I've just started using Fill Column Indicator for Emacs, which adds a vertical line on editing window to indicate the fill column.
I figured out that turn-on-fci-mode function could trigger the the bar.
I wanted it to start at the time when Emacs starts, so I also included it in the .emacs file.
The changes in the .emacs files are as follows:
(add-to-list 'load-path "~/.emacs.d/custom")
(require 'fill-column-indicator)
(turn-on-fci-mode)
Unfortunately, the line does not come up, even though running the function manually brings up the line.
fci-mode is buffer local. That means you need to turn it on for each buffer individually - setting it in your .emacs will set for one buffer, possibly just the splash screen, and not have any influence on the rest of your buffers.
To turn it on for all buffers, you need to use the following code in .emacs:
(define-globalized-minor-mode global-fci-mode fci-mode (lambda () (fci-mode 1)))
(global-fci-mode 1)

Run certain Emacs init commands only in GUI mode

Is there a way to run certain commands (from init.el) only when I am in GUI mode and not in terminal mode. I want to set a certain color scheme when I run the GUI version, but that scheme screws up the terminal window's colors pretty badly. I'm looking for some variable/function which would look something like this:
(if gui-mode (color-scheme-blah))
or:
(unless terminal-mode (color-scheme-blah))
You want something like
(if window-system (color-scheme-blah))
window-system can be 'x or 'mswindows or possibly even other values, but it's always nil when you are on a terminal.
To generally test for a graphic display you want to use the following:
(display-graphic-p &optional DISPLAY)
It returns non-nil if DISPLAY is a graphic display. Using for example the window-system variable also works, but requires you to refer to a specific environment (such as X or Microsoft Windows).
When using emacsclient and frames GUI or terminal mode is not necessarily a global concept. See the very useful answer to my question at https://superuser.com/questions/165335/how-can-i-show-the-emacs-menu-in-gui-emacs-frames-but-not-in-tty-frames-when-usin .

Is there any way to get Ediff to not open its navigation interface in an external window?

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!

configure emacs variables for a specific function

I run an email client in a separate emacs window (usually connecting to gnuserv), for example,
emacs -f wl
(the email client being Wanderlust, which probably doesn't matter much).
Is it possible to make emacs remember my preferred
window layout,
main window dimensions,
fonts, colours, etc.,
to set these up only when wl is called? Roughly speaking, if I want to have black background in the email client but white otherwise?
I'm especially interested in keeping the window layout because the default one has to be manually adjusted every time wl is loaded.
There is default-frame-alist variable that allows you to specify the default appearance and behavior for a new frame (frame is what you call a seperate Emacs window). Though it overrides the settings for all frame, you can advise your function to mask its global value and set it yours. Something like this:
(defadvice wl (around wl-frame-settings activate)
(let ((default-frame-alist (append
'((width . 82) (height . 36)
(cursor-color . "#ffa200")
(tool-bar-lines . 0)
;; ...
)
default-frame-alist)))
ad-do-it))
As TJ pointed out, this solution might have a drawback that it gets invoked too late. TJ's wlwrapper may be a better way.
Building on Török Gábor's answer, you can use any of a number of packages to store and restore window/frame configurations, many are listed here. The various window layout packages all have their quirks, so you'll have to find which one you like (there are so many packages b/c everyone finds something they don't like about the existing packages and roll their own).
With respect to fonts and colors, some can be customized on a frame-by-frame basis, see the info page for frame parameters.
With respect to how to hook it to the function 'wl, you can use advice if you want (I love using it), but it might be much more straight-forward to just either customize 'wl itself, or write a wrapper which does the frame/window configuration loading and then calls 'wl. Then your invocation might have to change to:
emacs -f wlwrapper
The way your emacsclient is configured (or, for older Emacsen, gnuclient) may be what's causing TG's solution not work. I'd probably use the 'wlwrapper solution, customizing emacsclient to re-use an existing frame, then inside 'wlwrapper modify the 'default-frame-parameters and then call 'wl. That way you ensure you create the frame after the parameters are set.
Something like this untested:
(defun wlwrapper ()
"wrapper for 'wl which sets up window/frame configurations"
(let ((default-frame-alist (append
'((width . 82) (height . 36)
(cursor-color . "#ffa200")
(tool-bar-lines . 0)
;; ...
)
default-frame-alist)))
;; if 'wl doesn't create a frame
(select-frame (make-frame))
(wl)
;; now use which ever window saving package you want
))