Org-mode strike-through color - emacs

Strike-through texts (like this: +text+) in Org-mode are black by default. I want to make them gray. The problem is, I can't find the place to customize it. I've tried M=x describe-face, and the result is "default face", which is puzzling. Doesn't Org-mode have a place to configure the strike-through color?

Customize the org-emphasis-alist variable with M-x customize-variable. Find the list entry where the "marker character" is + and choose the "Font-lock-face" option in the "Value menu" popup. Input the value of a face of your choosing, whose exact look you can customize the usual way, for example with M-x customize-face.
Or, more succinctly:
(require 'cl) ; for delete*
(setq org-emphasis-alist
(cons '("+" '(:strike-through t :foreground "gray"))
(delete* "+" org-emphasis-alist :key 'car :test 'equal)))

Related

Color tags based on regex emacs org-mode

I'm using org-mode and I want all my tags beginning with # to be colored in blue.
Is it possible and how to do it ?
Best regards
The following answer uses the built-in mechanisms of org-mode. The variable org-tag-faces accepts a regexp for the tag, which is the car of the cons cell. The function org-set-tag-faces sets a global variable org-tags-special-faces-re, which combines the tags of the aforementioned cons cell(s). The global variable org-tags-special-faces-re is used by org-font-lock-add-tag-faces to re-search-forward through the org-mode buffer -- locating the matching tags and applying the appropriate face based on the function org-get-tag-face. The original version of the function org-get-tag-face looked for an exact match of the tag found (i.e., the key argument to the function assoc). The revised version of org-get-tag-face adds an additional key search for #.* and returns the proper face if the key is found -- this is necessary because the tag itself will usually look something like #home or #office, whereas our context regexp is #.*.
(require 'org)
(add-to-list 'org-tag-faces '("#.*" . (:foreground "cyan")))
;; Reset the global variable to nil, just in case org-mode has already beeen used.
(when org-tags-special-faces-re
(setq org-tags-special-faces-re nil))
(defun org-get-tag-face (kwd)
"Get the right face for a TODO keyword KWD.
If KWD is a number, get the corresponding match group."
(if (numberp kwd) (setq kwd (match-string kwd)))
(let ((special-tag-face (or (cdr (assoc kwd org-tag-faces))
(and (string-match "^#.*" kwd)
(cdr (assoc "#.*" org-tag-faces))))))
(or (org-face-from-face-or-color 'tag 'org-tag special-tag-face)
'org-tag)))
You can use font-lock-add-keywords, for example, evaluating the following org source block should color the '#' tag blue.
#+TITLE: Tag face
#+BEGIN_SRC emacs-lisp
(defface org-tag-face
'((nil :foreground "blue" :background "#f7f7f7"))
"org tag face")
(font-lock-add-keywords
'org-mode
'((":\\(#[^\:]+\\):" (1 'org-tag-face))))
#+END_SRC
* test :#tst:
* test2 :tst:
After evaluating, revert the buffer or call font-lock-flush and font-lock-ensure to update font-locking.

emacs highlight background changes

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")

How do you color specific letters in emacs?

In a new and hopefully very simple emacs mode I would like every instance of 'a' to be #0000FF and 'b' to be #DF0101. Thus far I haven't found a way to do this despite lots of googling. Ideally it would happen in realtime, as you typed.
http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Highlight-Interactively.html
http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Font-Lock.html#Font-Lock
I use this for my Navi minor mode:
;; Adding Navi to the syntax highlighting of emacs mode.
First to make new faces, with their colors, in my case green for the success font for letter "t", and cyan for "Navi" and "navi".
If needed, read about font-lock.
(make-face 'font-lock-Navi-face)
(set-face-foreground 'font-lock-Navi-face "cyan")
(make-face 'font-lock-success-face)
(set-face-attribute 'font-lock-success-face nil :foreground "green")
Now to add the 'keywords' (regexp) to which to attach:
(defun add-custom-keywords()
"adds a few keywords for emacs mode"
;
(font-lock-add-keywords nil
'(
("Navi\\|navi" . 'font-lock-Navi-face)
;; here you can see that I highlight the letter "t" in " t " when spaced,
;; or with a parenthesis\newline around it
("\\s-t\\s-\\|\\s-t)\\|\\s-t\n" . 'font-lock-success-face)
)
)
)
You can replace Navi ("or" is here "\\|") or navi with simply your letter, "a" or "b", so "a\\|b" and then give the face to it.
; This is the hook to activate when the mode is triggered
(add-hook 'emacs-lisp-mode-hook 'add-custom-keywords)
The last part ensures that this font will be "real-time", and every time you open the file.
add-font-lock-keywords is for user customizations, mostly. If you're writing the mode yourself, it's much better to just set font-lock-defaults with an appropriate value.
Check sample-mode on the emacswiki for some example.

Emacs buffer-local font

For all my tasks I use URW Chancery L font in Emacs. But for some tasks,
like org-mode tables, shell or sunrise-commander, I would like to set mono-width font.
So, my question, how can I do it? All I found about it is set-default-font, which is not what I want.
Faces (i.e. the objects used to specify appearence of text such as font, color, ...) are mostly global in Emacs, although they can also be set on a frame basis, so you can do the above by creating a separate frame and change the `default' face to use in that frame.
This said, Emacs can also now also change face's appearence for specific buffers via face-remapping. E.g.
(face-remap-add-relative 'default '(:family "Monospace"))
should make the current buffer use Monospace. So adding the above to org-mode-hook might just solve your problem.
This snippet sets the "Arial" font family only in C mode:
(defun set-my-font ()
(overlay-put (make-overlay (point-min) (point-max) nil nil t)
'face '(:family "Monospace")))
(add-hook 'org-mode-hook 'set-my-font)
Replace with org-mode-hook with the desired mode(s), and it should work as well.
This solution effects creation of buffer-local font by setting the font family property of an overlay over the entire buffer. The overlay's face property only specifies the font family (Monospace), and Emacs redisplay is smart enough to merge it with other text properties, such as the colors specified by font-lock.
Did you try to customize org-table ?
You can modify it with org-menu > Customize > Customize > org-table
or use the command line
M-x set-face-font RET org-table RET -PfEd-DejaVu Sans Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1
Use tab to auto-complete and see other available fonts
Finaly you could also directly modify you init.el to have something like
(custom-set-faces
'(org-table ((t (:foreground "LightSkyBlue" :family "DejaVu Sans Mono")))))

Emacs AucTex Latex syntax prevents monospaced font

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.