I would like to display HTML with bold and italic text in Emacs tooltips. The solution I am trying is like this:
(let ((html "regular <b>bold</b> regular <i>italic</i> regular\n")
(bufname "* render-html-tmp*"))
(with-current-buffer (get-buffer-create bufname)
(erase-buffer)
(insert html)
(shr-render-region (point-min) (point-max))
(tooltip-show (buffer-string))))
In the * render-html-tmp* buffer the bold and italic text show up all right, but in the tooltip all the five words are in plain regular text, without bold or italic. Changing the value of x-gtk-use-system-tooltips has no effect.
At the same time, when I go to the end of the * render-html-tmp* buffer and do (insert (buffer-string)) there, or copy the buffer contents into the kill ring and yank it into a new buffer, the bold and italic attributes do show up correctly in the inserted or yanked text. So my basic idea should be right, and I am at my wit's end trying to figure out why I am not seeing these attributes in the tooltip.
What's going on, and how to make the bold and italic text show up in the tooltip?
tooltip-show overrides the face property of the string that is passed into it and replaces it with its own tooltip property:
(x-show-tip (propertize text 'face 'tooltip)
(selected-frame)
params
tooltip-hide-delay
tooltip-x-offset
tooltip-y-offset))
...
As the OP mentions in a comment, defining a modified tooltip-show to pass text directly to x-show-tip instead of doing the (propertize text ...) and calling that from his code resolves the problem.
Related
It is possible to specify text modifiers such as bold, italics, strikethrough, etc. in a .org file very easily (see link).
Similarly, is there any way to specify text color for just a small section of a .org file such that the text is appropriately colored in the exported html file? I think this would be quite useful while taking highlighted notes fast.
Expected behavior:
This is a sample sentence in normal text color.
<font color="red">
This is a sample sentence in red text color.
</font>
<font color="green">
This is a sample sentence in green text color.
</font>
You can use a macro:
#+MACRO: color ##html:<font color="$1">$2</font>##
* This is a test
This is a sample sentence in normal text color.
{{{color(red,This is a sample sentence in red text color.)}}}
{{{color(green,This is a sample sentence in green text color.)}}}
with the limitation that the second argument cannot contain a comma (and maybe some other characters).
If you are annoyed by macros. Then add the following to your Emacs config,
(org-add-link-type
"color"
(lambda (path)
(message (concat "color "
(progn (add-text-properties
0 (length path)
(list 'face `((t (:foreground ,path))))
path) path))))
(lambda (path desc format)
(cond
((eq format 'html)
(format "<span style=\"color:%s;\">%s</span>" path desc))
((eq format 'latex)
(format "{\\color{%s}%s}" path desc)))))
example in org-mode:
- This is [[color:green][green text]]
- This is [[color:red][red]]
org-faq
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")
I'd like to quickly generate text in a buffer that looks like this:
(fact "This is some text which will hang out
only on this part of the screen, ideally
automatically flowing to the correct
margins as I type."
(+ 1 1) => 2
;; more Clojure tests...
)
I have an Elisp keybinding which quickly spits out a starting template and puts my cursor in the right place:
(global-set-key "\C-of" (lambda ()
(interactive)
(insert "(fact \"\"\n\n )")
(backward-char 6)))
Now, when I am typing in the string portion ("This is some text..."), it'd be awesome if I could get Emacs to automatically flow text to the "correct" margins. Is there some way Emacs can be made to adjust margins and wraparound behavior based on where you're typing? At least, the first time you are typing there?
Barring that, for a given selection of text, how can I do the equivalent of fill-region, but with the desired left and right margins? Currently fill-region deletes all space between fact and "This is...., and left-justifies the rest.
There might be a simpler way that I'm overlooking now, but I would just do this:
Configure the text block in a temporary buffer, by doing this there:
a. Set fill-column to the width of the text block that you want.
b. Put the text at the beginning of the line, i.e., not indented.
c. Fill the text.
d. Use indent-rigidly to indent the text to the column you want, except for the first line.
Insert into your target buffer (fact followed by the indentation you want for the first line of the text block. Then insert the contents of the temporary buffer. Then insert whatever other text/code you need.
IOW, I would separate filling the text block from indenting it.
The following seems to work for the moment for my alternative (weaker) case:
;; Set up Midje fact with mark inserted at beginning of comment text
;; (refill as needed in appropriate columns, using C-oF).
(global-set-key "\C-of" (lambda ()
(interactive)
(insert "(fact \"\"\n\n )")
(backward-char 6)
(set-mark (point))))
;; Perform the refill operation to properly reformat the text string
;; in a Midje fact, started with C-of:
(global-set-key "\C-oF" (lambda ()
(interactive)
(set-left-margin (mark) (point) 37)
(fill-region (mark) (point))))
I expect I'll have to tweak this as I get experience using it, but it is pretty close. Still, it'd be nice to figure out how to have this happen automatically, while I'm typing inside the string.
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)))
How can I put clickable text in emacs minibuffer?
For example, this code makes clickable text in a text buffer and it works fine for me.
(let ((map (make-sparse-keymap)))
(define-key map (kbd "<down-mouse-1>")
'(lambda() (interactive) (message-box "it works!")))
(add-text-properties 1 5 `(keymap, map
mouse-face highlight)))
However, similar code for minibuffer doesn't work correctly
[...]
(with-current-buffer (window-buffer (minibuffer-window))
(message "link")
(add-text-properties (point-at-bol) (point-at-eol)
`(keymap, map
mouse-face highlight))))
As a result a text is put in a minibuffer without these properties.
I also tried (propertize but result is same.
[...]
(message (propertize "link"
'mouse-face 'highlight
'keymap map)))
What's wrong with this?
Thanks
message writes to the echo area, not the minibuffer.
The minibuffer is not active. Even if you use insert instead of message you will not see the text there.
What is it that you are really trying to do? What is the context where you want to insert such propertized text in the minibuffer? The minibuffer is active when, e.g., input is being read. You can initiate reading and insert the text there when it is active.