emacs 23 and font size - emacs

I am using emacs 23 on my Ubuntu netbook edition. Every app, automatically goes to fullscreen (so does my emacs). But depending on the font size (:height), I get a smaller working window.
If I go to :height normal I get the full area but the fonts are HUGE!
any ideas?

Your window manager is broken. emacs resizes itself when you change the font size (this happens during startup). Your window manager should tell emacs that emacs was resized by the window manager, at which point everything will work normally.
Anyway, start emacs as "emacs --daemon" and connect with "emacsclient -c" and you should not notice this problem.

OK, so actually I added this to my initfile:
(add-hook 'after-make-frame-functions
(lambda (frame)
(progn
(add-to-list 'default-frame-alist
(cons 'height
(/ (x-display-pixel-height)
(frame-char-height)))
(add-to-list 'default-frame-alist
(cons 'width
(/ (x-display-pixel-width)
(frame-char-width))))))))
and now the window is the same size as the full screen. If you are setting your fonts inside of the after-make-frame-functions hook then it is important that this comes first in your initfile, (I think because hooks are run in reverse order) but if you're just setting the fonts then this should work OK anywhere.
Of course for maximum safety you could put this and your 'set fonts' stuff into the same defun, with this coming after the fonts have been set.
EDIT:
This is a slightly more forceful way to do it, in case that doesn't work.
This gives me some issues though, really you would probably want to subtract the height of the top panel from the height you're setting it to.
(add-hook 'after-make-frame-functions
(lambda (frame)
(progn
(set-frame-height frame
(/ (x-display-pixel-height)
(frame-char-height)))
(set-frame-width frame
(/ (x-display-pixel-width)
(frame-char-width))))))

The font size issue can be fixed simply by selecting a different size font as the default font (Options->Set Default Font), then saving the options (Options->Save Options). Emacs seems to have issues with font point sizes matching system sizes (there's discussion about X standard DPIs versus GTK standard DPIs), but if you select one that works it will stay the same.
To get the window to come up maximized correctly, I've found there's an issue with the frame alist not accounting for the minibuffer correctly as well as the different font sizes not triggering the frame to resize correctly. If you set the initial-frame-alist to include (fullscreen . fullwidth) and (minibuffer-lines . 1) it accounts for the minibuffer size correctly and comes up with the correct width, forcing an effect as if you resized the window by hand to the maximum visible area (not quite the same as maximizing). You can set these via Options->Customize Emacs->Settings Matching Regexp... Then typing initial-frame-alist. Set two new parameters and values, "minibuffer-lines" to "1" and "fullscreen" to "fullwidth".
Removing the "minibuffer-lines" parameter will give you a full screen width window that's the wrong height, and removing the "fullscreen" parameter means nothing resizes correctly. Attempting to set "fullscreen" to "fullscreen" gives the same issue as setting nothing, and "fullscreen" to "fullheight" gives blank space only across the height and not the width when a smaller font size is used.

Related

emacs - startup window size changed from default to maximum

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.

Emacs Line Height

I am trying to set the line height of text in an Emacs buffer so there is space above and below the letters. From the documentation, I infer that the line-height text property may help me to accomplish this.
There is also a line-spacing variable which I can set like (setq-default line-spacing 0.25). This kind of works, except it does not produce space before text, only after it. I don’t like the way this looks when using modes like show-paren-mode, since it “dips” down:
Undesired current behavior (“hanging”)
Desired behavior mockup (vertically-centered)
I'd like to vertically-center the text.
I have discovered that I can temporarily get the effect I want with the following code:
(add-text-properties (point-min) (point-max)
'(line-spacing 0.25 line-height 1.25))
However, in some modes the properties go away in regions where I start typing. How do I make that top and bottom spacing the default? (Hooks won't work.)
Update
TLDR: I've succumbed to the fact that you can't really reliably achieve this natively with Emacs. You need to patch the font itself to include extra spacing. So, I created this script to take care of that.
Old/Incomplete Answer
TLDR: Add this somewhere in init file:
;; Set the padding between lines
(defvar line-padding 3)
(defun add-line-padding ()
"Add extra padding between lines"
; remove padding overlays if they already exist
(let ((overlays (overlays-at (point-min))))
(while overlays
(let ((overlay (car overlays)))
(if (overlay-get overlay 'is-padding-overlay)
(delete-overlay overlay)))
(setq overlays (cdr overlays))))
; add a new padding overlay
(let ((padding-overlay (make-overlay (point-min) (point-max))))
(overlay-put padding-overlay 'is-padding-overlay t)
(overlay-put padding-overlay 'line-spacing (* .1 line-padding))
(overlay-put padding-overlay 'line-height (+ 1 (* .1 line-padding))))
(setq mark-active nil))
(add-hook 'buffer-list-update-hook 'add-line-padding)
Increase or decrease the line-padding value to your liking.
This answer pretty much just summarizes the information in the above question, answer, and comments, so I suggest reading those first.
I use an overlay instead of text properties because it behaves more nicely when adding new text to the buffer (especially via copy/paste).
The buffer-list-update-hook is used as a means of identifying when a new buffer has been created and thus would need to have the overlay applied.
For performance reasons, to not continuously add overlays, the existing padding overlay is deleted if it aleady existed.
As the doc says, line-height is a text (or an overlay) property. It is not a variable.
Try (setq-default line-spacing 20).
line-spacing is a frame parameter or a buffer-local variable. Its value can be an integer number of pixels or a floating-point number specifying spacing relative to the frame's default line height. The doc says nothing about giving it a list value, such as (32 64).
And if you are using Emacs in terminal mode then none of this applies. As the doc says about that:
On text terminals, the line spacing cannot be altered.
Try "Help => More Manuals => Emacs Lisp Reference" and from there type i text properties RET. This will hopefully clarify the situation. As for your specific request, I don't think there's a simple way to get what you want right now. You might like to M-x report-emacs-bug about the display appearence of the paren-highlighting.

EMACS :: linum-mode and size of font (unreadable line numbers)

When using linum-mode in emacs and when increase font by M-x text-scale-increase, there is the one thing that bothers me. Font for line numbers have same size as reading and don't fit into left-margin on left side of buffer!
1
Normal font-size, OK
2
Increased font-size, no longer readable FUUUUU
What I'd really like to have:
When increase/decrease font I want one of these to work
then increase/decrease width of left-margin (resp. left-fringe) accordingly
then don't change font for left-margin but increase/decrease spacing between line numbers
Does anybody have some suggestions?
Thanks, guys
Have a look at these two links:
my question on the same issue
my workaround for this issue
It works quite well enough for my needs.
Examples:
1
The easiest, most straightforward solution I've seen is to set the line numbers to a fixed height. This can be accomplished easily, in accordance with user78810's answer: https://unix.stackexchange.com/questions/29786/font-size-issues-with-emacs-in-linum-mode/146781#146781
To wit, add the following line in your emacs config (or to your dotspacemacs/user-config function, if you're using spacemacs):
(eval-after-load "linum"
'(set-face-attribute 'linum nil :height 100))
M-x customize-face [RETURN] linum-mode
I think I can fix that problem with the following code:
(require 'linum)
(defun linum-update-window-scale-fix (win)
"fix linum for scaled text"
(set-window-margins win
(ceiling (* (if (boundp 'text-scale-mode-step)
(expt text-scale-mode-step
text-scale-mode-amount) 1)
(if (car (window-margins))
(car (window-margins)) 1)
))))
(advice-add #'linum-update-window :after #'linum-update-window-scale-fix)
It seems to work, at least with 24.5.
I would comment on the solution based on customize-face if I could. It works well for me. The actual face is linum rather than linum-mode, at least in my emacs-24.3.1. In the customization buffer, I clicked on "Show all attributes" and then set the face height to 100 tenths of a point. If a fixed-size face for the line numbers is acceptable to you (as it is to me) the solution based on customize-face is straightforward.
You can disable linum-mode and use display-line-numbers-mode instead which is part of Emacs since version 26 and scales well when increasing font size.
E.g. your config can look like:
;; (global-linum-mode 1)
(global-display-line-numbers-mode)

Centering text in emacs window

Inside just one lonely emacs frame I switch frequently between editting 70-column text files (LaTeX) and 120-column programs (.h/.cpp files). I'd like to continue to use just one emacs frame, without resizing it or creating additional frames.
Here is the problem. The width of my window is about right for editting the 120-column programs, but during the extended text editting sessions, the 70 columns appear on the left side of the window. At the end of the day in front of a laptop, my neck seems to have acquired a semi-permanent tilt to the left.
Are you aware of a method to make the text appear centered, while still making the text files remain jagged on the right?
You could try narrowing the frame by increasing the fringe size. For example:
(set-fringe-style '(200 . 200))
would shave 200 pixels off each side of the main text area, leaving the work area 400 pixels narrower but still centered. To return to the regular view,
(set-fringe-style 'default)
will revert the fringe to the normal size.
And you can wrap that up inside some advice, which might work well for you if you stick to using just a single window:
(defadvice switch-to-buffer (after switch-to-buffer-adjust-fringe activate)
"depending on major mode, switch fringe style"
(if (memq major-mode '(latex-mode))
(set-fringe-style '(200 . 200))
(set-fringe-style 'default)))
Note: Update the list (latex-mode) to contain whatever modes you want to have the large fringes.
EmacsWiki has a page on shrink-wrapping frames. You could use the libraries and code referenced there to automatically shrink and grow your Emacs frame as necessary.
;; Add left and right margins, when file is markdown or text.
(defun center-window (window) ""
(let* ((current-extension (file-name-extension (or (buffer-file-name) "foo.unknown")))
(max-text-width 80)
(margin (max 0 (/ (- (window-width window) max-text-width) 2))))
(if (and (not (string= current-extension "md"))
(not (string= current-extension "txt")))
;; Do nothing if this isn't an .md or .txt file.
()
(set-window-margins window margin margin))))
;; Adjust margins of all windows.
(defun center-windows () ""
(walk-windows (lambda (window) (center-window window)) nil 1))
;; Listen to window changes.
(add-hook 'window-configuration-change-hook 'center-windows)
Add your file extensions above, below "md" and "txt".

is it possible to move the emacs minibuffer to the top of the screen?

I've started coding on a 30 inch monitor and am wondering if it's possible to move the minibuffer to the top of the screen in emacs? google searches aren't showing up anything.
Cheers
Nimai Etheridge
Have a look at the documentation for the default-minibuffer-frame and initial-frame-alist vars. It sounds like you may be able to have a separate frame for your minibuffer (which you could position at the top of the screen), and then generate minibufferless frames which utilise it.
Note that in initial-frame-alist it states that "If the value calls for a frame without a minibuffer, and you have not created a minibuffer frame on your own, a minibuffer frame is created according to minibuffer-frame-alist", which sounds like exactly what would be needed.
There are ways of saving and restoring frame configurations, so if this worked you could probably recreate the layout automatically when emacs starts.
Edit:
Very basic example/proof-of-concept below for using this frame arrangement. The minibuffer frame can't be deleted until the frames utilising it have been deleted. You'll run into trouble when you do things like maximising the editor frame, of course, so there would certainly be some work to do to try to make this system work in a more seamless fashion.
(setq default-minibuffer-frame
(make-frame
'((name . "minibuffer")
(width . 80)
(height . 1)
(minibuffer . only)
(top . 0)
(left . 0)
)))
(setq new-frame
(make-frame
'((name . "editor")
(width . 80)
(height . 30)
(minibuffer . nil)
(top . 50)
(left . 0)
)))
Naturally, you can also combine this with scottfrazer's method of moving the modeline to the top.
This could possibly be handled in the window-setup-hook?
You should also look at the built-in frame.el and dframe.el libraries. Functions like dframe-reposition-frame may provide a convenient way of keeping the minibuffer frame 'attached' to the top of the active editing frame.
The variable minibuffer-auto-raise can also be configured to raise the minibuffer frame whenever the minibuffer is activated, which may mitigate the need to have it visible the rest of the time.
I'm pretty sure you can't move the minibuffer itself, but you can sort-of-ish make the mode line be on top:
(setq-default header-line-format mode-line-format) ; Copy mode-line
(setq-default mode-line-format nil) ; Remove mode-line
This will override things like Info that use the header line, but it's probably as close as you'll get without hacking C source.
Use a standalone minibuffer frame. This shows how:
http://www.emacswiki.org/emacs/Dedicated_Minibuffer_Frame
http://www.emacswiki.org/emacs/oneonone.el
Either look at that code to get an idea or just use it directly. You need only customize the minibuffer frame position settings:
1on1-minibuffer-frame-left -- Position of left edge of minibuffer frame, in pixels.
1on1-minibuffer-frame-top/bottom -- Position of top (or bottom) of minibuffer frame, in pixels.
After being stuck on these answers for a good while, I discovered clemera's answer for emacs 26+ to be useful:
For Emacs 26 and later you can use emacs-maple-minibuffer or ivy-posframe if your are using ivy.
Those packages let you configure to popup a minibuffer frame at any position, including the current window top/bottom. The docs of those packages describe how to set them up.