Like glucas, I'm doubtful that prettify-symbols-mode is actually what you want to be using for your auto-translate library; however the question seems useful in general and I was curious about the character composition rules. I came up with the following:
(defun my/add-visual-replacement (from to)
"Make `prettify-symbols-mode' replace string FROM with ...
prettify-symbols-alist is a variable defined in ‘prog-mode.el’.
Automatically becomes buffer-local when set.
So your setq sets it only for a single buffer.
While setq-default could be used to set a default value, what you should do is use the appropriate major mode hooks to setq the value to a sensible value for each of the modes you are interested in....
If you want the symbols to be prettified in the whole org file, just define prettify-symbols-alist in the buffer and enable prettify-symbols-mode.
But a better solution would ensure that these symbols are prettified only in the src blocks (and according to the language mode). Note that they are when editing the source block through org-edit-src-code (since ...
According to the documentation for prettify-symbols-alist, you cannot use regular expressions here:
Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL (a string, not a regexp) will be shown as CHARACTER instead.
pretty-symbols-mode uses regexp-opt internally, which creates a big regular expression from all the strings in the ...
That should work just fine, but you'll need to "reload" prettify-symbols-mode for the buffer you're working with.
For instance after starting emacs with -q and doing M-x prettify-symbols-mode to turn it on, in my scratch buffer I did the following:
;; we're in lisp-interaction mode where ^J runs eval-print-last-sexp
;; starting with prettify-symbols-mode ...
I found a solution by looking into the implementation of ``prettify-symbols-mode''.
;; Special form for section etc.
(let ((spec '(("\\\\part\\b" font-latex-sectioning-0-face "#")
("\\\\chapter\\b" font-latex-sectioning-1-face "##")
("\\\\section\\b" font-latex-sectioning-2-face "###")
The closest I have gotten to replicating this is to customize the way emacs sets the font for characters for each mode I want to change
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords 'latex-mode ;; you can change the mode here
'(("\\(wordone\\).*?wordtwo" 1 '(face nil display "∑"))))
This will replace ...
Modes usually inherit from each other. For example, java-mode inherits from prog-mode which inherits from fundamental-mode. Similarly, many modes inherit from special-mode. If you add a function to both fundamental-mode-hook and special-mode-hook, you should already cover many major modes.
When symbols are composed with prettify-symbols-mode is controlled by prettify-symbols-compose-predicate. By default this will only compose symbols if they are at a word boundary and not inside a comment or string. It checks the parser state with syntax-ppss to verify that the point is outside of a comment or string. We can change this to only check if we ...
I presume you have global-prettify-symbols-mode enabled, which is a globalized minor mode. They can be a bit tricky.
Calling (prettify-symbols-mode -1) in c-mode-hook wouldn't work because the mode isn't being enabled until later.
Using (setq prettify-symbols-alist '()) in c-mode-hook might work? It won't prevent the buffer-local mode being enabled, but it ...
The symbol boundaries are controlled through the function registered at the variable prettify-symbols-compose-predicate.
That function is prettify-symbols-default-compose-p by default. If that function returns non-nil the symbol that starts at START, ends at END, and has match-string MATCH is accepted for prettification.
Citation from prog-mode.el:
You could add another matcher using the same regexp as prettify-symbols-mode, i.e. something like this:
`((,(regexp-opt (mapcar 'car prettify-symbols-alist) t)
(0 (when (funcall prettify-symbols-compose-predicate