orgmode - change code block background color - org-mode

Below code will change html export background color to #eff0fe:
#+ATTR_HTML: :style background-color:#eff0fe;
#+BEGIN_EXAMPLE
hello world!
#+END_EXAMPLE
like below:
How can we change the background color when edit in emacs?
I saw Pretty fontification of source code blocks document but sounds like it doesn't work for me!

Another approach (which I think is more general) is explained in this page and I have copy-pasted the snippet here. It will only change the code block, and not the #+BEGIN, #+END, or #+RESULTS lines.
The example below will darken the code block by 3 percent (notice the number 3 at the last parameter) relative to the background color of your emacs theme. However, if you change your theme during editing the color of the code block will stay the same.
(require 'color)
(set-face-attribute 'org-block nil :background
(color-darken-name
(face-attribute 'default :background) 3))
Output using a light theme:
Output using a dark theme:
You can modify further the code block color for individual programming language. The example below will modify the code block color for emacs-lisp and python.
(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
("python" (:background "#E5FFB8"))))

Sounds like some face name changed, below config works:
(custom-set-faces
'(org-block-begin-line
((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
'(org-block
((t (:background "#EFF0F1" :extend t))))
'(org-block-end-line
((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
)
Output:

Related

Emacs org mode: background color of latex fragments (with `org-highlight-latex-and-related`) : which variable to change?

Ok, so my org-mode latex fragments have a slightly off background color, but only when I:
(setq org-highlight-latex-and-related '(native))
As seen here
It looks similar to the background highlighting functionality as involved in ~~ (code).
Does anyone know what to do?
BONUS:
I'm using doom emacs and the gruvbox theme.
TRIED:
I don't think this is related to the fragments themselves a la org-format-latex-options (as seen in many other posts)
This is NOT helped by setting font-latex-math-face :background
HINTS:
I feel like it IS related to the face org-latex-and-related, but I can work out how the chance the background, when I 'customise' the face i get the following:
(defface org-latex-and-related
(let ((font (cond ((assq :inherit custom-face-attributes)
'(:inherit underline))
(t '(:underline t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,#font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,#font))
(((class color) (background light))
(:foreground "SaddleBrown"))
(((class color) (background dark))
(:foreground "burlywood"))
(t (,#font))))
"Face used to highlight LaTeX data, entities and sub/superscript."
:group 'org-faces
:version "24.4"
:package-version '(Org . "8.0"))
Answering my own question.
As usual, tecosaur got there first and gives a good breakdown of the internals.
The code that does the magic is
(require 'org-src)
(add-to-list 'org-src-block-faces '("latex" (:inherit default :extend t)))

Emacs colors. why it is gray on current line? zenburn theme

I installed Prelude on my emacs24. I'm using ubuntu 12.04
It worked perfectly the first time I used it, but all the next times it doesn't.
On my current line the font color is gray so it's hard to see what I write. Previously it was a Bold case, keeping any color the line had for reserved words.
How can I fix this?
or also the empty lines with spaces are all yellow
I've been trying to fix it on the:
~/.emacs.d/elpa/zenburn-theme-20130716.1457/zenburn-theme.el
file but I can't find a solution... I think the problem could be between this lines:
;;;;; hl-line-mode
`(hl-line-face ((,class (:background ,zenburn-bg-05))
(t :weight bold)))
`(hl-line ((,class (:background ,zenburn-bg-05)) ; old emacsen
(t :weight bold)))
Thanks!
You can change the background and foreground to whatever you want, or turn it off completely. You can add bold or underline or overline or slant, or whatever floats your boat. One of my very first projects was to take the settings from color-theme and put it into my .emacs file and I haven't used a specific color theme since. Oh, and of course you want to open your .emacs or init file to see if there are any settings that conflict with the color theme you are using.
(global-hl-line-mode 1) ;; highlight current line -- see hl-line.el
(custom-set-faces
'(highlight ((t (:background "grey80" :foreground "black" :bold t)))) ;; highlight current line
)
Important:
Add to .bashrc file:
export TERM=xterm-256color
and I found the perfect configuration for me. Here it goes:
;;;;; hl-line-mode
(custom-set-faces
'(highlight ((t (:background "grey20" :foreground nil :bold t)))) ;; highligh\
t current line
)
This way you keep every color for reserved words all bold and a gray background for the current line. Everything will be beautiful =)

Customizing highlighting faces in Emacs: Only change the background color

Is there any way to define a face in Emacs (e.g. highlight such as hl-line) so that it only changes the background color (and have Emacs use the foreground color as if the word was not highlighted).
More specifically, I tried the following on the tango-dark theme
(custom-set-faces
'(region ((t (:inherit nil :background "RoyalBlue4"))))
'(highlight ((t (:inherit region :background "dark olive green"))))
'(hl-line ((t (:inherit highlight)))))
and, as can be seen below, region highlighting does respect the foreground font (i.e. it only changes the background color):
                     
but the highlighting of the current line does't:
                       
Why? and how can I get the same effect with hl-line?
Update:
This seems to a bug in the tango-dark theme (a builtin theme of Emacs). The code works well with the default theme (which loads with emacs -Q). I posted this on the official bugs mailing list.
I struggled with this some time ago, and it seems to be a bug of the color theme.
I've come up with a workaround, however. This works for me:
(load-theme 'tango-dark t)
(set-face-attribute 'highlight nil :foreground 'unspecified)
I had a bit similar problem:
(add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(when (display-graphic-p frame)
(custom-set-faces '(region ((t (:inherit nil :background "RoyalBlue4")))))
)

Strike through headlines for DONE tasks in Org

I'd really like to have my DONE task strikken through in Org-mode. Following the snippet from http://lists.gnu.org/archive/html/emacs-orgmode/2007-03/msg00179.html (via Sacha Chua's blog):
(setq org-fontify-done-headline t)
(custom-set-faces
'(org-done ((t (:foreground "PaleGreen"
:weight normal
:strike-through t))))
'(org-headline-done
((((class color) (min-colors 16) (background dark))
(:foreground "LightSalmon" :strike-through t)))))
This however doesn't work for me (colors are changed but no strike-through). I think it might be due to the solarized theme I use: https://github.com/sellout/emacs-color-theme-solarized
Unfortunately I couldn't fix it myself... If I look at customize-face of org-done Strike-through has value "On", but no visual effect.
Thank you very much!
If you are using a light background the snippet needs to be modified, the original author likely used a dark theme.
The key line is:
((class color) (min-colors 16) (background dark))
You could replace (background dark) with (background light), or just remove the background s-exp completely to work in both dark and light themes.
((class color) (min-colors 16))
After an eval-buffer on init.el it should work for your light themes. I did a quick test with solarized light and it works.

Change Emacs syntax highlighting colors

I'm running Emacs, editing files in C++ mode and PHP mode. I love syntax highlighting as a concept, but the default colors are a travesty. I can barely read some of them: way too dark. What is the easiest way to change their values? I can't seem to find anything about this on the web. I don't even mind changing the binary as I'm compiling my own Emacs. I just want to find the place where it says blue is #0000FF and change it to #AAAAFF for example.
I find it easiest to use color-theme for this sort of thing.
But if you don't want to do that, put the cursor over the offending text, and hit M-x customize-face. It should default to the face that the cursor is over.
See 49.1.6 Customizing Specific Items.
Two ways - you can install the package color-theme, which has lots of nice schemes to select and is easier to do it by hand. The by-hand looks like this (in your .emacs file)
(custom-set-faces
custom-set-faces was added by Custom.
If you edit it by hand, you could mess it up, so be careful.
Your init file should contain only one such instance.
If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "lightyellow2" :foreground "gray20" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :width normal :family "liberation mono"))))
'(background "blue")
'(font-lock-builtin-face ((((class color) (background dark)) (:foreground "Turquoise"))))
'(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))
'(font-lock-constant-face ((((class color) (background dark)) (:bold t :foreground "DarkOrchid"))))
'(font-lock-doc-string-face ((t (:foreground "green2"))))
'(font-lock-function-name-face ((t (:foreground "SkyBlue"))))
'(font-lock-keyword-face ((t (:bold t :foreground "CornflowerBlue"))))
'(font-lock-preprocessor-face ((t (:italic nil :foreground "CornFlowerBlue"))))
'(font-lock-reference-face ((t (:foreground "DodgerBlue"))))
'(font-lock-string-face ((t (:foreground "LimeGreen"))))
...
etc. etc.
You can also type
`M-x customize-face RET`
which will give you all the customizations to set, ultimately end up in your .emacs file.
Put the cursor on a face ("color") that you want to change. Hit C-u C-x =. That will tell you which face(s) are present at that position, and it will let you click to customize it/them. Save your customizations.
If you don't care about color highlighting at all, or none of the previous answers work for you (or take too much time and effort to figure out), here is a very simple solution that will get rid of colors altogether.
Typing the following will get rid of colors:
M-x global-font-lock-mode
You can also do this as an interim step to allow you to actually see everything your screen to try any of the above answers. In my case, this was very useful because the color of certain key pieces of text which would allow me to change colors were themselves nearly invisible - for instance, the prompt of M-x.
If you want the change to be permanent, you can add this to your .emacs file:
(setq-default global-font-lock-mode nil)
Starting with Emacs 24.1, you can use M-x customize-themes to select a colour theme.
Emacs comes with a dozen or so themes with varying brightness and colourfulness, so you'll most likely find something that mostly matches your preferences.
You can also find more colour themes installable through MELPA at https://peach-melpa.org/ - no, that web site seems to be down. You can search for "theme" at melpa.org, but it doesn't show any screenshots.