I am using Emacs -nw in Ubuntu. I like to turn on linum-mode to see line numbers on the left margin, but the numbers are put right next to my code.
I would love it if there could be some 'padding', like 1-character long, between line number and code. sorry I can't post an image since they are asking for 10 reputation, which I dont have:(
How can I do this?
You can use the variable linum-format to achieve this. Its value can either be a format string or a function which is called with line number as an argument. emacswiki has a couple of example of setting it to a format string
1) The following adds a space after the line-number
(setq linum-format "%d ")
2) You can also add a solid line separator
(setq linum-format "%4d \u2502 ")
I guess the above are sufficient for your needs. You can also find an example of using a function as linum-format here. Add whichever format suits your needs to your init file
In addition to the other answer(s) in this thread, options for putting distance between the line numbers and the text include, but are not limited to, adjusting the fringe width (and also set the color if you so choose).
The fringe is like a vertical ruler that runs from the top to the bottom of the buffer -- the left fringe is sandwiched between the line numbers and the text. It can be invisible if it is the same color as the default background of the user, or it can be a different color.
(setq-default left-fringe-width 10)
(setq-default right-fringe-width 0)
(set-face-attribute 'fringe nil :background "black")
Related
Does org-mode have a way to correctly align numbered lists (and other indented items) when using a proportional font, like Helvetica?
Thanks!
Not a full fix, but I use the following in my init.el:
;; Ensure the indent face is always fixed pitch. This matches my
;; headline font, and therefore we indent consistent with heading font
;; pitch.
(add-hook 'after-init-hook
(lambda ()
(set-face-attribute 'org-indent nil :inherit 'fixed-pitch)))
This gets the left-hand edge of indents working for me (so they match the indent of headings, for example), but isn't quite right if the bullet/list line is sufficiently long to wrap. Still, it fixes the main problem for me which was these items appearing to be at a higher level than the headings.
I wan to change the width of emacs which can fit the width of LCD.
In addition to the details in the thread that #lawlist posted in his comment, the simplest way to get fullwidth is to set the frame parameter accordingly. The following will do it:
(set-frame-parameter (selected-frame) 'fullscreen 'fullwidth)
However, to have this happen automatically at startup, you should set the parameter in your initial-frame-alist somewhere in your .emacs file:
(setq initial-frame-alist
'((fullscreen . fullwidth)))
Beside elisp methods given in thread mentioned by #lawlist in the comment you can also set emacs geometry in ~/.Xdefaults file, eg.:
Emacs.geometry: 100x29+-2+-2
These four numbers represent width, high and position of upper left corner (optional)
Now just run xrdb ~/.Xdefaults and from now on emacs will always start with this geometry.
The good thing about .Xdefaults method is that you can set in one place parameters (not only geometry) for different programs but using similar syntax, for example
! geometry
Emacs.geometry: 100x29
xpdf.geometry: 80x25
xterm*geometry: 70x20
! foreground color
Emacs*foreground: white
xpdf*foreground: black
xterm*foreground: light grey
! background
Emacs*background: #445566
xpdf*background: white
xterm*background: #262729
! other stuff
xterm*toolBar: true
xpdf*urlCommand: /usr/bin/firefox %s
I wrap all my code at 80 columns, and there are times where the Emacs window is wider than 80 columns and there is a lot of unused whitespace on the right side.
I would like to position the Emacs buffer, so all the text is displayed in the middle of the window.
This is different to centre aligning text (more akin to the whitespace on either side of the text when viewing pdfs).
I think this can be achieved by dynamically adjusting the fringe mode widths, depending on the current window size, but I'm not sure where to start. Any ideas?
As demonstrated here this is indeed possible:
(set-fringe-mode
(/ (- (frame-pixel-width)
(* 80 (frame-char-width)))
2))
However, as I am testing this I seem to have more luck with using margins, at least when also resizing my frame:
(defun my-resize-margins ()
(let ((margin-size (/ (- (frame-width) 80) 2)))
(set-window-margins nil margin-size margin-size)))
(add-hook 'window-configuration-change-hook #'my-resize-margins)
(my-resize-margins)
Here is a function which should do what you want, using margins instead of fringes (since I tend to display buffer boundaries in the fringe and I find it becomes ugly if the fringe is too large).
(defun my/center (width)
(interactive "nBuffer width: ")
(let* ((adj (- (window-text-width)
width))
(total-margin (+ adj
left-margin-width
right-margin-width)))
(setq left-margin-width (/ total-margin 2))
(setq right-margin-width (- total-margin left-margin-width)))
(set-window-buffer (selected-window) (current-buffer)))
You ask to display the buffer in the center of the window, which just moves some of the extra whitespace to the left of the buffer, from the right.
How about a solution that eliminates that extra whitespace instead? If that is acceptable, here are two approaches.
If the buffer is alone in its frame, then you can fit the frame to the buffer, using library fit-frame.el. I bind command fit-frame to C-x C-_. This saves space not only within Emacs but for your desktop. (Library zoom-frm.el lets you also shrink/enlarge a frame incrementally, so you can save space by shrinking a frame when you don't need to see its content in detail.)
If not (so the buffer is shown in a frame where there are multiple windows), and if the buffer's window has another window to the left or right of it, then you can do one of the following:
2a. If the buffer's window has another window to the left or right of it, then you can use command fit-window-to-buffer. But you will also need to set option fit-window-to-buffer-horizontally to non-nil.
2b. Use C-{ (shrink-window-horizontally), followed by C-x z z z..., to incrementally shrink the window width (removing the extra whitespace).
2c. Load library face-remap+.el. Whenever you use text-scaling (e.g. C-x C- or C-x =), the window size grows or shrinks along with the text size, so you don't get extra whitespace added at the right when you shrink the text. This is controlled by user option text-scale-resize-window.
Center window mode
https://github.com/anler/centered-window-mode
Global minor mode that centers the text of the window.
If another window is visible the text goes back to normal if its width is less than "cwm-centered-window-width."
Modern answer is https://github.com/rnkn/olivetti or https://github.com/joostkremers/writeroom-mode, both worked immediately for me where other things did not
My linum margin is wide (about 6 characters). In most examples on the web, it's not. How can this be changed?
There are no specific parameters set by myself. I am using emacs mac port. There is a custom theme, but it does set anything.
linum-format controls the formatting. If you (setq linum-format 'dynamic) it should adapt the width on the fly. If you want to hardcode the number of columns, you could do, say, (setq linum-format "%5d") for a 5-column number.
How to change the color of some outer or inner border? Whenever I change border-color of the frame, I don't see any changes and it is not allowing me to change the border width.
So far, what did work was
(set-frame-parameter (selected-frame) 'internal-border-width 15)
which adds some frame around the buffer.
But I don't know how to change the inner color. Does anyone know how to have a nice border/frame around the working space?
Any method goes.
EDIT: Added what sds accomplished:
I would like actually to have area around it to have a different color, so outside of the red.
I found an example (read: this is what I was after all along) of a frame I would like to accomplish.
It does appear that you cannot change the border width of an existing frame, but you can create a new frame with the border width you want:
(frame-parameter (make-frame '((border-width . 10))) 'border-width)
==> 10
However, the appearance of the new frame does not differ (as far as I can tell on ubuntu) from that of all the other frames (where border-width is 0);
which, I guess, is not all that surprising given that the window manager may not pay attention to [the border-width] you specify.
The more relevant question, I think, is what are you really trying to do?
Do you want Emacs windows (known as frames in the Emacs world) to differ visually from all the other windows?
If this is what you are after, then you have to realize that window decorations are the domain of the window manager (as mentioned above), and applications (like Emacs) can only affect those using "hints", and window managers are free to ignore them.
However, you can change the parameters of the fringe face:
(set-face-background 'fringe "red")
which should make the Emacs frame appearance very distinct.
I think you are specifying the fringe. You can set the fringe colour with this in your colour-theme function if you are using one.
(defun color-theme-whatever ()
"A color theme"
(color-theme-install
'(color-theme-whatever
((fringe ((t (:background "#111" :foreground "#444"))))))))