My emacs (Aquamacs with AucTex) changes font size (in e.g. LaTeX mode) to show the syntax - like this:
Unfortunately this ruins the point of a monospaced font - e.g. my comments do not align. How do I solve this problem?
For the specific example of sections, chapters, etc., add the following to your .emacs:
(setq font-latex-fontify-sectioning 'color)
Edit
Here is the config I usually use to customise the AUCTeX formatting:
;; Only change sectioning colour
(setq font-latex-fontify-sectioning 'color)
;; super-/sub-script on baseline
(setq font-latex-script-display (quote (nil)))
;; Do not change super-/sub-script font
(custom-set-faces
'(font-latex-subscript-face ((t nil)))
'(font-latex-superscript-face ((t nil)))
)
;; Exclude bold/italic from keywords
(setq font-latex-deactivated-keyword-classes
'("italic-command" "bold-command" "italic-declaration" "bold-declaration"))
If you find a solution to this, the beers are on me. The best I've been able to come up with so far is to put the following in my .emacs somewhere and run the function after loading a mode that does this (org-mode does it too).
(defun fix-fonts ()
(interactive)
(mapc
(lambda (face)
(set-face-attribute face nil
;; :family (if (string= system-type "darwin")
;; "Menlo"
;; "Inconsolata")
:width 'normal
:height 1.0
:weight 'normal
:underline nil
:slant 'normal))
(remove 'default (face-list))))
I don't do the family thing anymore, because I didn't have time to figure out a good way to programatically get it right and it doesn't seem to matter, but your mileage might vary. Also, I don't set anything on the "default" font because some of the other values are relative and need that fixed reference point.
Related
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")
In GNU Emacs, I see that I can set different faces for foreground type in different modes, e.g.:
(custom-set-faces
'(message-header-to ((t (:foreground "LightGoldenrod1" :weight bold)))))
How can I set the background color for the frame by mode? Such that, for e.g., org-mode background would take whatever the color-theme defines it as, but message-mode background would be black?
Something like this, except that the below doesn't work:
(custom-set-faces
'(message-mode-frame ((t (:background "black")))))
Here is a quick example to do it by frame -- i.e. where it will affect every buffer in the frame:
(add-hook 'post-command-hook 'change-my-background-color)
(add-hook 'change-major-mode-hook 'change-my-background-color)
(add-hook 'window-configuration-change-hook 'change-my-background-color)
(defun change-my-background-color ()
(cond
((eq major-mode 'org-mode)
(set-background-color "honeydew"))
((eq major-mode 'text-mode)
(set-background-color "blue"))
(t
(set-background-color "red"))))
And, here is a change the buffer color example:
(defun buffer-background-red ()
(interactive)
(setq buffer-face-mode-face `(:background "red"))
(buffer-face-mode 1))
To do it on a window basis is not presently possible; however, here is a link to changing the modeline color as to the active window.
https://stackoverflow.com/a/20936397/2112489
"Entire frame, i.e. entire background of message-mode"
this phrase make me think author mixed up frame and window in Emacs. Each frame can contains several windows. While *-mode can refer to each buffer, i.e. window.
So if you want to set background color by mode for each buffer with it (but not for frame) then better use mode hooks like here
I use the following to ensure that lambda symbols etc are displayed using a specific font
(set-face-attribute 'default nil :family "PragmataPro")
(set-face-attribute 'default nil :height 130)
;; over-ride "fontset-defult" for all unicode characters
(set-fontset-font "fontset-default" 'unicode "PragmataPro")
And use a pretty lambda font-lock when working in scheme,
(defun pretty-lambdas ()
(font-lock-add-keywords nil
'(("(\\(lambda\\)\\>" (0 (prog1 ()
(compose-region (match-beginning 1)
(match-end 1)
?λ)))))))
this works fine when using the default emacs theme, but if i change theme M-x load-theme: - the λ becomes some kind of "eastern" symbol, even though the character glyph for λ is provided by the face.
Any ideas? Is the load theme over-riding something?
-- EDIT --
I though the problem has solved itself, with the regular face it is now fine, but it still happens with italics.
I'm getting the error Unable to load color "unspecified-bg" [16 times] when using emacsclient -c. I've started up emacs using emacs --daemon. This seems to mean that my custom faces won't load.
When starting emacs as usual, and then using M-x server-start, then this problem doesn't happen at all. How can I get emacsclient -c to load the faces properly?
Here's the relevant code:
(custom-set-faces '(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :foundry "unknown" :family "Inconsolata")))))
I'm not 100% sure this would fix your problem, but you really should be using color-theme for syntax highlighting. Custom is meant for beginning emacs users, so I'd suggest you try out color-theme and see if it works. Here's how I have it set up on my machine:
Download the package from the color-theme homepage.
Put the color-theme folder somewhere like ~/.emacs.d/color-theme/.
Make sure this folder is in your load-path. I took the following code from a Steve Yegge post:
In your .emacs:
(defvar emacs-root "~/.emacs.d/")
(labels
((add-path
(p)
(add-to-list
'load-path
(concat emacs-root p))))
(add-path "lisp")
(add-path "color-theme-6.6.0")
(add-path "cedet-1.0"))
(require 'color-theme)
Then you define your color theme:
;; Color-theme
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
;; Set custom color theme
(defun color-theme-mine ()
"My custom color theme"
(interactive)
(set-cursor-color "#ffffff")
(color-theme-install
'(color-theme-mine
;; Super-light grey on Dark grey
((foreground-color . "#e0e0e0")
(background-color . "#151515")
(background-mode . dark))
(font-lock-comment-face ((t (:foreground "#106010")))) ;; Forest Green
;; More definitions below
;; ...
(color-theme-mine)) ;; end eval-after-load
This will load color-them-mine when you start emacs. You can see all available color themes by typing M-x color-theme <TAB>. To see the full list of faces available, use the command M-x list-faces-display.
Sounds like this might be bug #4776: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=4776#5. If not, consider filing a bug report for this one, using M-x report-emacs-bug.
For example, how can I make a minor mode that changes the default foreground color to gray, and upon exiting the minor mode, the foreground color is back to black? This mode might be useful when you don't like certain text to be seen over your shoulders.
For now, I run the following code to turn text color to gray:
(set-face-attribute 'default (selected-frame) :foreground "darkgrey")
And the following code to get back.
(set-face-attribute 'default (selected-frame) :foreground "SystemWindowText")
But this affects all buffers.
You can use buffer-face-mode based on overlays, it also lets to change the background of text in your buffer.
(make-face 'hard-to-read-font)
(set-face-attribute 'hard-to-read-font nil :background "darkgrey" :foreground "grey")
(define-minor-mode hard-to-read-mode
"This mode might be useful when you don't like certain text to be seen over your shoulders."
:init-value nil :lighter " hard-to-read" :keymap nil
(if hard-to-read-mode
(progn
(font-lock-mode nil)
(buffer-face-mode t)
(buffer-face-set 'hard-to-read-font))
(progn
(font-lock-mode t)
(buffer-face-mode nil))))
;; change this to mode you need
;; or turn it on manually
;; (add-hook 'text-mode-hook
;; (lambda ()
;; (hard-to-read-mode t)))
update: You know, this isn't secure. It works against human eyes, but anyone can use camera and then just increase contrast to read the text.