So I have been using emacs a lot lately. And I have been noticing that the window resizes for a second when it starts up. Is there a way to fix that?
Here is the GIF of what I'm talking about.
To prevent Emacs from resizing its window after startup, put all geometry and font options on the command line or .Xdefaults file rather than in .emacs or other lisp init files.
The initial Emacs frame is drawn before running the lisp startup files, but the X config and command line options have already been read.
As your GIF is mainly showing a width change, with only a minor change in height and no change in the position of the frame, I suspect it is most likely font settings rather than size settings that you need to look for.
My Sample Code (Ensure to put these codes at the first line of your init.el file)
(setq frame-inhibit-implied-resize t) ;; prevent resize window on startup
(setq default-frame-alist '((width . 120) (height . 42)))
(defun x/disable-scroll-bars (frame)
(modify-frame-parameters frame '((horizontal-scroll-bars . nil)
(vertical-scroll-bars . nil))))
(if (display-graphic-p)
(progn
(scroll-bar-mode -1)
(tool-bar-mode -1)
(fringe-mode '(8 . 0))
(add-hook 'after-make-frame-functions 'x/disable-scroll-bars))
(progn
(menu-bar-mode -1)
(setq-default
left-margin-width 1
right-margin-width 0)))
The core is (setq frame-inhibit-implied-resize t).
I've got this line in my .emacs to go fullscreen on startup:
(add-to-list 'default-frame-alist '(fullscreen . maximized))
I run Emacs from WSL with an X11 server on Windows 10. I could set some -geometry to make it not resize into a minimal initial window, but that seemed to be flaky and random. This happened with both Xming and Vcxsrv. It happened even with -Q so in my case it was not related to anything in my startup files.
I haven't tried Cygwins X11 server, but when I tried the evaluation version X410 (available in the Windows Store) it did not have the same problem.
hi: Each time I insert some text in emacs , it will highlight the newly added text. I wonder how to change the background color of the highlight, because the highlight background color is very close to the font color , as a result, I can hardly recognize the code that I am writing.
thank you soooo much
For issues with fonts (which Emacs calls faces) inside of Emacs, it is often helpfull to know the function 'list-faces-display'. You can call this with M-x and it will list all faces defined in the current frame. This can be helpfull both identifying which face is problematic, it will also give you its name which can be used to modify the face. For instance to change the foreground colour of the face named "button" you can call something like this:
(set-face-foreground 'button "cyan")
The effect will be immediately visible. Many aspects of faces can be changed, including colour, font familiy and font size.
Obviously, this will not help you if the problematic behaviour stems from the terminal emulator you are using, as it would appear from some of the comments to your question, then the problem is outside of Emacs and cannot be fixed from inside of Emacs. Even so, knowing about 'list-faces-display' is usefull.
I had this exact question and managed to solve it using the following ways. But I also had another thing in mind: a marker to show which lines are modified.
For tracking changes between the saved file and the buffer, we should use the highlight-changes-mode. But before enabling that mode, we need to prepare some stuff as explained beautifully here for the line marks:
;; a part to add the fringe marks to the gutter. To change the shape, read the explanation of it in this code.
(eval-after-load "hilit-chg"
'(progn
(defvar highlight-fringe-mark 'filled-square
"The fringe bitmap name marked at changed line.
Should be selected from `fringe-bitmaps'.")
(defadvice hilit-chg-make-ov (after hilit-chg-add-fringe activate)
(mapc (lambda (ov)
(if (overlay-get ov 'hilit-chg)
(let ((fringe-anchor (make-string 1 ?x)))
(put-text-property 0 1 'display
(list 'left-fringe highlight-fringe-mark)
fringe-anchor)
(overlay-put ov 'before-string fringe-anchor))
))
(overlays-at (ad-get-arg 1))))))
;; make the highlight-changes-mode reset when the file is saved
(add-hook 'local-write-file-hooks 'highlight-changes-rotate-faces)
(add-hook 'after-save-hook
(lambda ()
(when highlight-changes-mode
(save-restriction
(widen)
(highlight-changes-remove-highlight (point-min) (point-max))))))
make sure it is enabled globally except for buffers that start with ' and *
(setq highlight-changes-global-modes t)
(global-highlight-changes-mode)
make the mode to respect the syntax-highlighting
;; find the name of other faced using M-x ~list-faces-display~
(custom-set-faces
'(highlight-changes ((t (:background "dark green" :foreground nil)))))
(set-face-foreground 'highlight-changes nil)
(set-face-background 'highlight-changes "dark green")
I would like to use Emacs 24.2.1 in orgmode 7.9.3 on a data projector in class.
I can pre-visualize latex formulas using org-preview-latex-fragment (C-c C-x C-l), and
I can increase the font used to display the text using text-scale-increase (C-+).
The problem is that the math fonts are not increasing along the text fonts.
Is there a way to configure Emacs so that the math fonts are variable too?
Was this solved in a later version of orgmode (I was planning to wait for the end of the term to upgrade to version 8+, being afraid of having to invest a lot of time in updating my configuration).
A poor man's solution that works with advices and hooks is shown below.
Paste the code into your .emacs configuration file and re-start emacs. Afterwards, the equation images should be scaled at along with the text if you press C-+/-/0. They are just previews and their The bad thing is that the resolution is not enlarged. To get equation images with a good resolution hit C-c C-x C-l to regenerate the images. Note, that this sets the :scale property of the customization variable org-format-latex-options. The customization of this variable will be lost for the current emacs session.
You need a gnu-emacs with built-in imagemagick. Should be standard by now.
(defvar text-scale-mode-hook nil
"Hook run at end of command `text-scale-mode'.")
(defadvice text-scale-mode (after text-scale-mode-hooks nil activate)
"Run `text-scale-mode-hook' at end of command `text-scale-mode'."
(if (functionp text-scale-mode-hook)
(funcall text-scale-mode-hook)
(loop for hook in text-scale-mode-hook do
(if (eq hook 't)
(run-hooks (default-value text-scale-mode-hook))
(run-hooks hook)))))
(defun org-text-scale-eye ()
"Scale equation images according to text-scale-mode-amount."
(when (boundp 'text-scale-mode-amount)
(let ((relwidth (* (expt text-scale-mode-step text-scale-mode-amount))))
(loop for ol in (overlays-in (point-min) (point-max)) do
(when (eq (overlay-get ol 'org-overlay-type) 'org-latex-overlay)
(unless (overlay-get ol 'org-image-original-width)
(overlay-put ol 'org-image-original-width (car (image-size (overlay-get ol 'display) t))))
(let ((ol-disp-plist (cdr (overlay-get ol 'display))))
(setq ol-disp-plist (plist-put ol-disp-plist :type 'imagemagick))
(setq ol-disp-plist (plist-put ol-disp-plist :width (round (* relwidth (overlay-get ol 'org-image-original-width)))))
(overlay-put ol 'display (append '(image) ol-disp-plist))
))))
(force-window-update)
))
(add-hook 'org-mode-hook '(lambda () (add-hook 'text-scale-mode-hook 'org-text-scale-eye)))
(defadvice org-format-latex (before set-scale activate)
"Set :scale in `org-format-latex-options' to the scaling factor resulting from `text-scale-mode' and clear cache."
(let ((relwidth (expt text-scale-mode-step text-scale-mode-amount)))
(unless (= (plist-get org-format-latex-options :scale) relwidth)
(plist-put org-format-latex-options :scale relwidth))))
Actually, I had a look at the code in org.el:
The font height is regarded in the function org-create-formula-image-with-dvipng and the resolution option -D is set. Maybe, there goes something wrong. Furthermore, pityingly, in org-format-latex the images are cached and not reproduced after font size changes.
If you want to increase the size of the latex-formulas for one session in general with good quality you can set the :scale value of the customization option "Org Format Latex Options" in the group "org-latex" to a higher value.
Edit 2013-10-10 (marked as italic throughout the answer except the code, naturally): The :scale property of the option org-format-latex-options is now set automagically. Therefore, the above hack should be quite usable (such as the latex version mentioned below).
The same problem as you describe in the original-post exists for latex-preview. But, for that case there is a better solution:
(require 'face-remap)
(defadvice preview-inherited-face-attribute (after preview-inherit-local-face nil activate)
"Scale preview images with respect to buffer-local face"
(when (and text-scale-mode (eq attribute :height))
(setq ad-return-value (* (expt text-scale-mode-step text-scale-mode-amount) ad-return-value))))
After C-+/-/0 type C-c C-p C-d to re-generate all formulas of the document. Afterwards, the formulas have just the right size and the right resolution.
If switching to latex documents with preview is an option for you I would recommend it. I use org only for notes and time-tables with easy links.
For more descriptive documents I use latex documents with auctex/preview. But, I actually compile them only very seldom to a final pdf document. The preview is good enough. See the following Figure.
I have a document displayed in a doc-view buffer. However, the document is rotated 90 degrees left. Can I rotate a doc in emacs doc-view?
I also had this requirement. Sadly doc-view doesn't provide this functionality.
Also the image code used by emacs can't rotate images. So I created a function which utilizes ImageMagick to transform the png files stored in the cache dir and redisplay the current page:
(defun doc-view-rotate-current-page ()
"Rotate the current page by 90 degrees. Requires ImageMagick installation"
(interactive)
(when (eq major-mode 'doc-view-mode)
;; we are assuming current doc-view internals about cache-names
(let ((file-name (expand-file-name (format "page-%d.png" (doc-view-current-page)) (doc-view--current-cache-dir))))
;; assume imagemagick is installed and rotate file in-place and redisplay buffer
(call-process-shell-command "convert" nil nil nil "-rotate" "90" (concat "\"" file-name "\"") (concat "\"" file-name "\""))
(clear-image-cache)
(doc-view-goto-page (doc-view-current-page))))))
This is driving me crazy: I simply want Emacs to maximize to whatever screen resolution I have at startup. Ideally I like a cross-platform (Windows & Linux) solution that works on any screen resolution, but I can't even get it to work on just Window XP with even hard-coded sizes.
Here are what I tried:
Setting the initial-frame-alist with appropriate height/width
Setting the default-frame-alist
(Windows specific stuff) Sending message to the emacs windows telling it to maximize via (w32-send-sys-command 61488)
Tried this function which I found somewhere:
(defun toggle-fullscreen ()
"toggles whether the currently selected frame consumes the entire display
or is decorated with a window border"
(interactive)
(let ((f (selected-frame)))
(modify-frame-parameters
f
`((fullscreen . ,(if (eq nil (frame-parameter f 'fullscreen))
'fullboth
nil))))))
Tried the above methods in both beginning and end of my init file to try to eliminate interference from other init things.
Unfortunately, none of the above works!! For some of the above, I can see my emacs windows resizes correctly for a split second before reverting back to the smallish default size. And if I run the methods above after the initialization, the emacs windows DOES resize correctly. What in the world is going on here?
[p.s. there are other SO questions on this but none of the answers work]
Update:
The answers make me think that something else in my init file is causing the problem. And indeed it is! After some try-and-error, I found the culprit. If I commented out the following line, everything works perfectly:
(tool-bar-mode -1)
What in the world does the toolbar have to do with maximizing windows?
So the question now is: how can I disable toolbar (after all, emacs's toolbar is ugly and takes up precious screen real-estate) AND maximize the windows both in my init file? It is possibly a bug that toolbar interferes with the windows size?
Clarification: (tool-bar-mode -1) turns the toolbar off, but this line interferes with maximizing the Emacs windows. So if I try put functions to maximize windows and turn off the toolbar, the maximize part will fail; if the toolbar part is commented out, then the maximize part will work ok. It does not even matter what solutions I use (among the 4 that I listed).
Solution: (or at least what work for me now)
This is probably a bug in Emacs. The workaround is to disable the toolbar through the Registry, not in .emacs. Save the following as a .reg file, and execute that file in Windows Explorer:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\GNU\Emacs]
"Emacs.Toolbar"="-1"
(This solution is a working version of what OtherMichael suggested).
I found an answer a year-or-so back that explains you have to manipulate the registry to do things right:
To start Emacs maximized put this line
at the end of your ~/.emacs file:
(w32-send-sys-command 61488)
If you don't want the Emacs tool bar
you can add the line (tool-bar-mode -1) [NOTE: value is 0 on original page]
to your ~/.emacs file but Emacs won't
fully maximize in this case - the real
estate occupied by the tool bar is
lost. You have to disable the tool bar
in the registry to get it back:
[HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs\Emacs.Toolbar]
#="0"
If you look in the EmacsWiki under W32SendSys command-codes you'll find that 61488 is maximize current frame
This is the simplest fix that worked for me:
(w32-send-sys-command #xf030)
(add-hook 'window-setup-hook (lambda () (tool-bar-mode -1)))
Dudes, what's wrong with
emacs -mm ?
This starts Emacs fully maximized. Put it in your shortcut, it really depends on the window manager you use ; I myself just alias it in my .*shrc.
On a different but not unrelated note, I in fact start Emacs in a way that if it's already started, the selected file is just opened as a new buffer in my existing Emacs session :
if [ "$(pidof emacs)" ] ; then
emacsclient "$#"
else
emacs -mm "$#"
fi
This I put in a ~/bin/e and I just launch Emacs with "e".
I right-clicked a text file in the file manager, selected "open with another program" and entered "e", and now I just double click files and they all open neatly in the same session.
And everything is peachy and lispy :)
On X.org the system call is (since you asked originally for a cross-platform solution):
(defun x11-maximize-frame ()
"Maximize the current frame (to full screen)"
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
This works reliably on Emacs 24.5.1 (i686-pc-mingw32):
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
First, thanks for the tip on the bug with (tool-bar-mode -1); saved me a lot of trouble! I'd rather keep everything within the .emacs file (no registry mods for me), so if you turn on the toolbar before maximizing, and then turn it off again, you'll can maximize nicely:
(defun maximize-current-frame () "Resizes the current frame to fill the screen"
(interactive)
;; There is a bug in tool-bar-mode that prevents it from being
;; maximized, so turn it on before maximizing.
;; See http://stackoverflow.com/questions/815239/how-to-maximize-emacs-on-windows-at-startup)
(tool-bar-mode 1)
(w32-send-sys-command 61488)
(tool-bar-mode -1)
)
Another way to resolve such problem is put delay between
(menu-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(scroll-bar-mode 1)
and set-frame-* functions. For example:
(tool-bar-mode -1)
(when window-system
(run-at-time (format "%d sec" 1) nil '(lambda () (set-frame-position (selected-frame) 1 1)))
(run-at-time (format "%d sec" 2) nil '(lambda () (set-frame-width (selected-frame) 150 t)))
(run-at-time (format "%d sec" 3) nil '(lambda () (set-frame-height (selected-frame) 60 t)))
)
It is essential to put delay between set-frame-* functions also!
I encountered one command that seems to work (toggle-frame-maximized), which works on both Linux & Windows.
I just put that near the end of my init file after setting up everything, making the assumption that by the end of the setup everything won't be maximized, and voila, it works.
Hey - nice function! Thanks for posting
I think it may not be working for you because you have code that looks like the
following somewhere else in your init file. The default-frame-alist is being applied
after the frame is created. I removed the size and position elements and you function
works great on bootup of emacs.
(setq default-frame-alist
(list
(cons 'left 350)
(cons 'top 0)
(cons 'width 80)
(cons 'height 45)
......
If you really want to run Emacs full screen without window chrome (title bar and max/min/close button), then try the mode below. This worked for me with Emacs 23.3.1 on XP SP3.
http://www.martyn.se/code/emacs/darkroom-mode/
every one.
emacs 23.3.1,blow code is invalid. because (menu-bar-mode -1) can cause windows not
full-screen too.
(w32-send-sys-command #xf030)
(add-hook 'window-setup-hook (lambda () (tool-bar-mode -1)))
I search Eamcs wiki,find a useable method.
http://www.emacswiki.org/emacs/FullScreen#toc3
MS Windows
If you’re using MS Windows, and want to use “real fullscreen”, i.e, getting rid of the top titlebar and all, see w32-fullscreen at the site for darkroom-mode
Alternatively, a patch is available here that makes the fullscreen frame parameter really fullscreen on Windows.
To get a maximized window you can use: (w32-send-sys-command #xf030)
Attention! If you want that emacs starts maximized, you have to put this code into your .emacs file:
(defun jbr-init ()
"Called from term-setup-hook after the default
terminal setup is
done or directly from startup if term-setup-hook not
used. The value
0xF030 is the command for maximizing a window."
(interactive)
(w32-send-sys-command #xf030)
(ecb-redraw-layout)
(calendar)
)
(setq term-setup-hook 'jbr-init)
(setq window-setup-hook 'jbr-init)
(defun resize-frame ()
"Set size"
(interactive)
(set-frame-width (selected-frame) 110)
(set-frame-height (selected-frame) 33)
(set-frame-position (selected-frame) 0 1))
following is the last function called in my .emacs files it sets the height and width of the screen it does work on both emacs 22 and emacs 23 on debian and mac os x. set the height and width numbers according to your screen.
To disable the toolbar, add the line
(tool-bar-mode nil)
to your customization file (usually .emacs in your root directory).
emacs-full-screen-win32 project will help you :)
The following snippet from emacswiki worked fine from me:
(add to your startup config file)
(defun jbr-init ()
"Called from term-setup-hook after the default
terminal setup is
done or directly from startup if term-setup-hook not
used. The value
0xF030 is the command for maximizing a window."
(interactive)
(w32-send-sys-command #xf030)
(ecb-redraw-layout)
(calendar)
)
(setq term-setup-hook 'jbr-init)
(setq window-setup-hook 'jbr-init)