How to change default face for embolden text in Emacs? - emacs

I do love thin fonts, so I have following customisation in my .emacs:
(set-frame-font "NK57 Monospace-14:weight=light" t)
This works as expected, however this does not tells Emacs that it should render embolden text with lighter weight too, e.g. to use medium instead of regular weight, so there is dramatically difference in weights, see picture below.
How can I tweak this?

Well, it is possible to customise default bold face using customize-face command as was mentioned by lawlist (i.e. Easy Customization).
However, this is not enough in most cases, because of some packages or themes could introduce another customisations, which overrides default one (e.g. font-lock-function-name-face, font-lock-keyword-face) and could be found in face customisation menu too.

Related

How to set a monopaced font in code-blocks?

My standard font is a proportional one. When I edit markdown files I would like to have all sections that are indented by 4 or more spaces be shown in a monospaced font.
I do not use any special markdown mode. Therefore I would be ok if I had to to switch that behavior manually on for the current buffer. Although, my own mode for *.md-files would be need of course, but I have no idea how to do that (and is beyond the scope if this question).
The modes that are active for me are:
Enabled minor modes: Abbrev Auto-Composition
Auto-Compression Auto-Encryption Blink-Cursor
Column-Highlight Column-Number Desktop-Save File-Name-Shadow
Flyspell Font-Lock Global-Font-Lock Icomplete Line-Number
Menu-Bar Mouse-Wheel Shell-Dirtrack Show-Paren
Tooltip Transient-Mark
Yes, you do need a mode that highlights markdown code. (Try M-x package-install RET markdown-mode+ RET) If you have font-locking enabled (I suspect you have), the mode that you end up probably gives syntax highlighting for markdown.
Now, syntax highlighting is just alterations to font and color used. Once you have it on, you can customize the font face used for code by navigating over a code block and issuing M-x customize-face. My markdown mode has code blocks under markdown-pre-face; the face under cursor will be selected by default for you.
I prepared some screenshots to show the workflow. Determining what emacs allows for font family or foundry is bit of a dark magic, and I leave it to google to find out more about it. On linux systems there used to be an ugly little helper called xfontsel where you can preview different font families and foundries.
You can experiment without saving anything first by applying the changes without saving; when things look fine, you can "apply and save" in the customize mode.
I'm going to partially disagree with the argument that you can do what you are after. You can only partially do what you are after and it is a bit of a hack.
Basically, you can set different fonts for different faces. So, provided the text you want to display in a fixed width font has a different face definition, then you can change the font from a proportional font to a fixed width font. At least, that is the theory.
Unfortunately, the results tend to be less than you would hope.
The problem is that most modes do not define faces for all possible characters. Faces tend to only be used to make something stand out and that tends to mean something which is special in the mode - a heading, a bit of syntax etc.
The problem will be witht he 'default face - the face used when no other face is specified. The default face is not mode specific. If you set default face to a monospace font, that font will be used in all modes, not just in 'plain' characters within markdown mode. If any of your fonts in markdown mode are proportional, you will find that alignment in indentation will not look consistent. Depending on how you structure your buffer contents, this may or may not be an issue.
Personally, I gave up on using a proportioanl font as the default font under emacs a long time ago and have settled instead on using a fixed width font as the default and then defining proportional fonts for some speial purposes, such as org-mode headers.
some things you could try which might work, would be
File local variables for setting fonts just in markdown filtes. I've not tried this, but you may be able to use file local variables. You would probably want to create a markdown template which sets this up in new markdown filtes.
Make the face variables buffer local. You might be able to define a markdown-mode hook function which makes the face variables buffer local and sets them to a fixed width font.
Face definitions can use inheritance, so theoretically, if all the faces used inherit from default face and you do a file local variable or buffer local variable to set the default face, then all other faces should inherit that definition, so you shouldn't have to do it for every font in the buffer.

Customizing the Emacs Monokai Theme to have a more Sublime Text 2 look

I am using Emacs Prelude. I didn't find most of the custom themes comfortable. I really liked Sublime Text 2's Monokai theme, so I installed the Monokai theme ported for Emacs. Though it is more or less similar to Sublime Text 2's Monokai, there are some differences which I want to correct, so as get my Emacs Monokai more close to Sublime's Monokai.
For example I don't want every Python keyword to be the bold pinkish. I would be prefer keywords like class,def to have a blue color than the pink ones and I would prefer the function arguments to have an orange color.
The Emacs Monokai theme seems to color the variable name to an orange color, which I don't want. How do I implement this? I checked the monokai-theme.el file, but I don't know what variable to edit and what variable to add to give the features in color changes I mentioned above.
I suppose you're referring to this version of Monokai?
You'll be able to make some of your changes, but without doing a huge amount of work some of them won't be feasible. This theme uses font-lock to identify many of the things to be coloured, and font-lock identifies all Python keywords the same way.
Have a look through the various font-lock variables in that file. This will give you a good idea of what you can easily change. For example, if you want to change variables from orange to something else, change
'(font-lock-variable-name-face
(:foreground monokai-orange))
to use one of the other monokai- colour variables, or define your own.
If you're trying to figure out how a particular character is recognized by Emacs, move your cursor over that character and do C-u C-x = (C-u M-x what-cursor-position). This will show, among other things, the face for that character.

Changing the color of a specific piece of text in emacs without creating a theme

Is it possible to select a piece of text you're editing and change its color? I know it's possible to create a color theme that will color certain kinds of text (like for example coloring functions in a certain programming language), but is it possible to do a one time color change to a selected piece of text in a specific emacs document without creating a theme? thanks in advance.
A theme doesn't allow you to specify the color of arbitrary text in any case. It only describes a set of face to be used by font-lock.
To apply a face to an arbitrary piece of text, select the text, then M-: (add-text-properties (region-beginning) (region-end) '(face font-lock-warning-face))
See the faces section of the elisp manual on how to create a face.
Emacs also comes with the hi-lock package, which can highlight regexps or lines containing regexps. See manual
how about M-x highlight-phrase ?
I know six years is a pretty long time, but I stumbled across this question and, after a lot of research, I did not find anything nearly as objective as what I eventually dug out for myself.
To color say, the first 200 characters in your buffer, execute the command:
(put-text-property 1 200 'face (cons 'foreground-color "red"))
If you need help executing this command in emacs, here is one possibility among many:
Type ESC-x eval-expression.
Type or paste the above command in the mini-buffer after the prompt.
Press ENTER.
You might like to look at enriched-mode.
If you are in a buffer that isn't controlled by font-lock, you can use 'facemenu'.
For example, highlight a bit of text, then with the mouse, press C-mouse-2. You can then select a face (some combination of text properties with a name). You can also pick random forground or background colors.
If you Emacs is particularly old, I seem to remember something similar on M-g.
Try set-background-color, set-foreground-color, set-cursor-color.
Changes won't be saved with the document though.
Note:
When I try those functions, they don't set the region's color unless I go through the menus.
See http://www.emacswiki.org/emacs/HighlightTemporarily (and it need not be temporary).
You can "color" text by swiping it with the mouse, or matching it with a regexp, and several other ways. Library highlight.el, in particular, lets you "color" text in many ways.

Emacs: hl-line-mode conflicts with highlight-phrase

I highlight current line by evaluating:
(hl-line-mode)
It could also be set globally:
(global-hl-line-mode nil)
The problem is that this way line highlighting overrides highlight-phrase. So my question is: "how to highlight both current line and a given phrase in this line?"
Both highlight-phrase and hl-line apply faces that have a background color set. hl-line wins because it uses an overlay, and overlays always override text properties, which highlight-phrase uses. I suggest that you work around this by customizing the hi-yellow face to use a bright foreground color instead of a background color, or even a box.
So here's some, definetly not ideal, solution. Do:
M-x customize-face
emacs then asks you which one, and I did
hl-line
Then I turned off "inherit" flag (the last one), and turned on the "foreground" flag, - it was saying "black" - I made it red. After that You should save it all at the top of the page - either - for this seccion only, or for future sessions too.
That's it! This way current line text arrears of red font, while highlight-phrase highlights the phrase with yellow.
Edit: The previous solution that I posted doesn't work, but this one should.
Highlight has two modes, one for font-lock-enabled buffers (which uses font-lock) and one for without (which uses overlay). The solution I found was to simply force highlight to use overlay at all times, and thus have higher priority over hl-line (because shorter overlays have an implicitly higher priority, given the same value of priority).
To do this I went into hi-lock.el and replaced every instance of font-lock-fontified with nil. Be sure to M-x byte-compile-file afterwards in order to update hi-lock.elc.

How do I modify text while keeping the original fontification?

I'm writing a mode which is actually a glorified markdown reader. It's a read-only mode however, and though I'd like to change the faces for bold, italics, and links, I'd love to remove the decorations surrounding those faces. However, when I do so, I lose the fontification. Is there anyway to modify fontified-text to something that no longer matches any of the syntax regexes and still keep the fontification?
Org-mode does this for its link markup. I'm not a mode writer (yet), but Org-mode would be the first place I'd look for code that demonstrates how to do this. Oddly, it doesn't do it for any of its fontification: italic, bold, and underline all retain their markup.
Specifically, the code to hide the link markup is on line 4612 of org.el in version 7.01 of org-mode:
(if org-descriptive-links (add-to-invisibility-spec '(org-link)))
where add-to-invisibility-spec is actually supplied by a built in elisp file subr.el, and allows specific types of markup to be hidden. That would be the approach I would take, especially if the buffer is read-only.