How to change Hash color in rhtml-mode in Emacs - emacs

I'm using rhtml-mode in Emacs.
When I write a Hash in a way like :key => "value" then :key is properly colorized.
But with key: "value" style the colorizing doesn't work. Only color of : is changed.
I tried to change rhtml-mode a bit. The mode seems to load ruby-mode internally if the text if is braced in <% %> tag.
Oddly when I write a Hash in ruby-mode both type of writing are properly colorized.
I'm using default ruby-mode in Emacs24.
How can I find the place (by line number) where the color of Hash key is defined?

The short answer: C-h vrhtml-in-erb-keywords. This will open a buffer showing you the regexp for rhtml keywords. There will be a link straight to where it is defined in the elisp file. You can see its definition here.
Add the following to your .emacs file:
(add-hook 'rhtml-mode
(lambda ()
(font-lock-add-keywords nil
'(("\\([0-9a-zA-Z_]*:\\)" 1
font-lock-constant-face t)))))
This will make Emacs apply the colouring determined by font-lock-constant-face to anything that matches the regexp "\\([0-9a-zA-Z_]*:\\)". This might match more than you want, so you may want to fine tune it.
I'm not sure there's a particularly easy way to find out exactly where the colour for a given keyword is found. You can always do M-xdescribe-face with the point over the word you want information on. This will tell you how Emacs thinks it should be coloured - something like font-lock-keyword-face. C-h vfont-lock-keyword will tell you how Emacs decided that, but not in a very helpful way.
The simplest way is probably just to open the source code for the mode you're in and search in that for where it defines keywords. You can open the source code with C-h frhtml-mode, which will open a help buffer with a link to the source.

Related

emacs doremi: to change color-themes

I'm trying to get doremi working in emacs. Specifically, at this stage, to allow me to quickly scroll through a condensed list of color-themes and see each theme as I go through it. For this I would use the 'M-x doremi-color-themes+' command.
What I've done:
Installed color-themes (successfull)
Installed doremi.el, doremi-cmd.el, ring+.el and added
(add-to-list 'loadpath "~/elisp/themes")
(add-to-list 'loadpath "~/elisp/doremi/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-classic)
;; create a list of color themes to scroll through using 'doremi-cmd
(setq my-color-themes (list 'color-theme-classic
'color-theme-retro-green
'color-theme-gray30
'color-theme-subtle-hacker
'color-theme-jonadabian-slate))
(require 'doremi)
(require 'doremi-cmd)
(require 'ring+)
to the .emacs file.
What emacs does:
When I type the comand 'M-x doremi-color-themes+' into the mini-buffer it seems to accept that I've given it a valid command and tells me to use the and arrow keys to move through the list. But when I do that all that happens is the cursor moves up and down in the active window. No changing of color-themes.
Being somewhat new to emacs (and especially customising it) I'm sure I have missed a step or put something in the wrong place. Perhaps there's some sort of (setq 'bla-bla-bla (...)) I need to do?
Sorry for your trouble. Please state your Emacs version (M-x emacs-version), and your version of color-theme.el.
You do not need to require library ring+.el if you use Emacs 23 or later (its code was included in GnuEmacs 23.)
You do not need to use (color-theme-initialize) or (color-theme-classic). The former is done automatically by doremi-color-themes+.
Try starting from emacs -Q (i.e., no init file, ~/.emacs), to be sure there is no interference from stuff in your init file.
Your variable my-color-themes is not referenced anywhere. Instead of defining that variable, just customize user option doremi-color-themes. (Or leave its value nil, which means that all color themes will be cycled through.)
Feel free to contact me by email if you continue to have a problem. Or continue here, if you prefer.
[Just to be sure: you are using color-theme.el, right? There is a lot of confusion out there between Emacs "custom themes" and color themes. Do Re Mi supports both, but they are different critters.]
After a bit for back and forth with #Drew we found a solution to the problem.
It turned out the major problem was that I was using emacs in 'terminal mode' rather than as a GUI application. Bare in mind I'm using a mac.
In the context of Terminal, my arrow keys send escape sequences and so doremi cannot read the event as intended. So it just escapes and applies the message to the active buffer.
There is an answer.
By adding the following lines to my .emacs file (or whatever your init file for emacs is) I was able to redirect doremi to use two other keys. ie. not the up and down arrows.
(setq doremi-down-keys '(?n))
(setq doremi-up-keys '(?p))
Doing this tells doremi to use 'n' as the down key and 'p' as the up key. And all works just fine.
Because I am only new to the world of programming and computing I may often use incorrect terminology. If this is the case please let me know and I will edit accordingly for clarity and consistency.

how to prevent helm-swoop from returning symbol at point?

I would like to invoke M-x helm-swoop such that it does NOT return the symbol at point. I find that it always picks up undesired symbols, e.g. when I invoke M-x helm-swoop in org-mode, I get Swoop: \*, and I then have to delete the \* before I can enter my desired search term. How can I do this?
This has been bugging me as well, for exactly the same reason (swoop in an Org-mode buffer picking up heading characters), so this question motivated me to go and look.
Looking at the source, Helm-swoop calls helm-swoop-pre-input-function to populate the prompt, and by default this is set to a function that returns (thing-at-point 'symbol), which is what causes the problem in headings.
A quick test with the following in my init file seems to work:
(setq helm-swoop-pre-input-function
(lambda () nil))
This could certainly be improved by, for example, keeping the default behaviour in non-Org buffers but as I'm only really using swoop in Org buffers this is good enough for me.

How to disable underscore (_) subscripting in Emacs, TeX input method

On Emacs, while editing a text document of notes for myself (a .txt document, not a .tex document), I am using M-x set-input-method Ret TeX, in order to get easy access to various Unicode characters. So for example, typing \tospace causes a "→" to be inserted into the text, and typing x^2 causes "x2" to be inserted, because the font I am using has support for Unicode codepoints 0x2192 and 0x00B2, respectively.
One of the specially handled characters in the method is for the underscore key, _. However, the font I am using for Emacs does not appear to have support for the codepoints for the various subscript characters, such as subscript zero (codepoint 0x2080), and so when I type _0, I get something rendered as a thin blank in my output. I would prefer to just have the two characters _0 in this case.
I can get _0 by the awkward keystroke sequence _spacedel0, since the space keystroke in the middle of the sequence causes Emacs to abort the TeX input method. But this is awkward.
So, my question: How can I locally customize my Emacs to not remap the _ key at all when I am in the TeX input method? Or how can I create a modified clone (or extension, etc) of the TeX input method that leaves out underscore from its magic?
Things I have tried so far:
I have already done M-xdescribe-key on _; but it is just bound to self-insert-command, like many other text characters. I did see a post-self-insert-hook there, but I have not explored trying to use that to subvert the TeX input method.
Things I have not tried so far:
I have not tried learning anything about the input method architecture or its source code. From my quick purview of the code and methods. it did not seem like something I could quickly jump into.
So here is the solution I just found: Make a personalized copy of the TeX input method, with all of the undesirable entries removed. Then when using M-x set-input-method, select the personalized version instead of TeX.
I would have tried this earlier, but the built-in documentation for set-input-mode and its ilk does not provide sufficient guidance to the actual source for the input-methods for me to find it. It was only after doing another search on SO and finding this: Emacs: Can't activate input method that I was able to get enough information to do this on my own.
Details:
In Emacs, open /usr/share/emacs/22.1/leim/leim-list.el and find the entry for the input method you want to customize. The entry will be something like the following form:
(register-input-method
"TeX" "UTF-8" 'quail-use-package
"\\" "LaTeX-like input method for many characters."
"quail/latin-ltx")
Note the file name prefix referenced in the last element in the form above. Find the corresponding Elisp source file; in this case, it is a relative path to the file quail/latin-ltx.el[.gz]. Open that file in Emacs, and check it out; it should have the entries for the method remappings, both desired and undesired.
Make a user-local copy of that Elisp source file amongst your other Emacs customizations. Open that local copy in Emacs.
In your local copy, find the (quail-define-package ...) form in the file, and change the name of the package; I used FSK-TeX as my new name, like so:
(quail-define-package
"FSK-TeX" "UTF-8" "\\" t ;; <-- The first argument here is the important bit to change.
"LaTeX-like input method for many characters but not as many as you might think.
...)
Go through your local copy, and delete all the S-expressions for mappings that you don't want.
In your .emacs configuration file, register your customized input method, using a form analogous to the one you saw when you looked at leim-list.el in step 1:
(register-input-method
"FSK-TeX" "UTF-8" 'quail-use-package
"\\" "FSK-customized LaTeX-like input method for many characters."
"~/ConfigFiles/Elisp/leim/latin-ltx")
Restart Emacs and test your new input-method; in my case, by doing M-x set-input-method FSK-TeX, typing a_0, and confirming that a_0 shows up in the buffer.
So, there's at least one answer that is less awkward once you have it installed than some of the workarounds listed in the question (and as it turns out, are also officially documented in the Emacs 22 manual as a way to cut off input method processing).
However, I am not really happy with this solution, since I would prefer to inherit future changes to TeX mode, and just have my .emacs remove the undesirable entries on startup.
So I will wait to see if anyone else comes up with a better answer than this.
I did not test this myself, but this seems to be the exact thing you are looking for:
"How to disable underscore subscript in TeX mode in emacs" - source
Two solutions are given in this blogpot:
By the author of the blogpost: (setq font-lock-maximum-decoration nil) (from maximum)
Mentioned as comment:
(eval-after-load "tex-mode" '(fset 'tex-font-lock-subscript 'ignore))
The evil plugin for vim-like modal keybinding allows to map two subsequent presses of the _ key to the insertion of a single _ character:
(set-input-method 'TeX)
(define-key evil-insert-state-local-map (kbd "_ _")
(lambda () (interactive) (insert "_")))
(define-key evil-insert-state-local-map (kbd "^ ^")
(lambda () (interactive) (insert "^")))
When _ and then 1 is pressed, we get ₁ as before, but
when _ and then _ is pressed, we get _.
Analogous for ^.
As already explained in pnkfelix answer, it seems we have to make a personalized copy of the TeX input method. But here comes a lighter way to do that, without any file tweaking. Simply put the following in your .emacs :
(eval-after-load "quail/latin-ltx"
'(let ((pkg (copy-tree (quail-package "TeX"))))
(setcar pkg "MyTeX")
(assq-delete-all ?_ (nth 2 pkg))
(quail-add-package pkg)))
(set-input-method 'TeX)
(register-input-method "MyTeX" "UTF-8" 'quail-use-package "\\")
(set-input-method 'MyTeX)
The important part is the assq-delete-all line in the middle that remove all shortcut entries starting with _. It's a bit of a lisp hack but it seems to work. Since I'm also annoyed by the shortcuts starting with - and ^, I also use the following two lines to disable them :
(assq-delete-all ?- (nth 2 pkg))
(assq-delete-all ?^ (nth 2 pkg))
Note that afterwards you can M-x set-input-method at any time and indicate TeX or MyTeX to switch between the pristine TeX input method or the customized one.

Setting up RefTeX Tab completion in emacs

I am trying to make Tab completion work with RefTeX. When typing C-c [ and selecting the type of reference I have then a prompt in the minibuffer. When I know the beginning of the bib key I want to enter, say for instance Campbell2006, I would like to type Camp Tab and get Campbell2006 [sole completion].
I have managed to set it up for some documents but I do not understand exactly why it works for them and not for others. I have noticed that for the documents that have proper Tab> completion, the following line is added to the file name_of_tex_file.el created in a auto subfolder:
(TeX-add-style-hook "name_of_tex_file"
(lambda ()
(LaTeX-add-bibliographies
"absolute_path_to_bib")))
I think I obtained this results by adding %%% reftex-default-bibliography: absolute_path_to_bib at the end of my files but this is kind of a nuisance, especially when editing the same file on several computers.
Note that RefTeX is working because when I type C-c [ Camp Ret, I get a list (sometime a bit odd) with the Campbell2006 entry.
I have tried to set the %BIBINPUTS% environment variables with no success.
Adding (setq reftex-bibpath-environment-variables '("c:/path_to_bib_file/")) seemed necessary for the C-c [ Camp Ret method to work.
It has somehow the same defects as adding a %%% reftex-default-bibliography: to the end of the file and did not provided the Tab completion.
I have tried various combinations of /, //, \\ and \ as file separators when specifying files but I do not know exact which I should use (I'm using emacs in a windows environment). The issue might be as simple as that but as there are lots of parameters to try I fail do determine where is the problem.
What is the step-by-step method to make RefTeX work smoothly with bibliography, including the Tab completion?
EDIT:
Completion is possible according to the Reftex manual entry about the command reftex-citation:
The regular expression uses an expanded syntax: &&' is interpreted as and. Thus,aaaa&&bbb' matches entries which contain both aaaa' andbbb'. While entering the regexp, completion on knows [sic] citation keys is possible. `=' is a good regular expression to match all entries in all files.
it does not provide precise guidance on how to make it work though.
Kindahero suggests setting a list of the bib entries and use the completing-read command. This sounds sensible, however I would like to generate this list automatically and it seems feasible because it works with some of my documents.
The documentation of reftex-citation is a bit confusing. It promises completion on known citation keys but I believe "known" refers to keys that have been used previously in this session rather than all keys in the appropriate bibliography. You can use the LaTeX-add-all-bibitems-from-bibtex command defined below to load all keys in your bibliography:
(defun get-bibtex-keys (file)
(with-current-buffer (find-file-noselect file)
(mapcar 'car (bibtex-parse-keys))))
(defun LaTeX-add-all-bibitems-from-bibtex ()
(interactive)
(mapc 'LaTeX-add-bibitems
(apply 'append
(mapcar 'get-bibtex-keys (reftex-get-bibfile-list)))))
Suggestions on appropriate hooks to make this happen automatically are welcome.

How to highlight all occurrences of a word in an Emacs buffer?

Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as well? And if so, how?
It doesn't necessarily have to work exactly like Notepad++ (i.e., via selection); ideally, I would like to set up a key binding that causes all occurrences of the word under cursor to be highlighted.
It would be great if the highlights were permanent, i.e., moving point away from a highlighted word should not cause the highlight to be removed.
Also, it would be useful if there was a solution that made it possible to navigate between highlights (using custom key bindings).
The hi-lock suggestions are good. I think it's easier to use the M-x versions, though:
M-x highlight-regexp RET <REGEXP>
M-x highlight-phrase RET <REGEXP>
highlight-phrase is just a bit of sugar around highlight-regexp that ignores case and translates a space in the regex to match arbitrary whitespace. Handy.
Maybe highlight-symbol.el at http://nschum.de/src/emacs/highlight-symbol/ is what you are looking for:
Type C-s, then type the current word or type C-w. As a bonus, you can now hit C-s again to search for the word.
This is called incremental search.
What I use is idle-highlight
http://www.emacswiki.org/emacs/IdleHighlight
M-x idle-highlight sets an idle timer that highlights all occurences in the buffer of the word under the point.
To enable it for all programming modes, in ~/.emacs.d/init.el:
;; highlight words
(add-hook 'prog-mode-hook (lambda () (idle-highlight-mode t)))
Light-symbol will highlight whatever symbol point is over.
Alternately, you can use occur, which lists all lines matching a regexp. It's useful to quickly see all functions in a class.
Nobody mentioned symbol-overlay mode. It's basically a better rewrite of highlight-symbol-mode. "Better" as in, lacks bugs of original highlight-symbol (such as, temporary highlight getting stuck, or the temporary highlight disappearing for moving inside the highlighted word; or not being able to highlight symbols like *), better integrated, and maintained. See "Advantages" paragraph of its README.
You can install it as usual, with M-xpackage-install (make sure to update package list beforehand with package-list-packages). For reference, at the bottom I attached code I use to enable the mode and disable a few of the more advanced features which you may or may not want.
Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as well? And if so, how?
Once you enable overlay-symbol, occurrences on the screen will be shown for every word that you put cursor upon after a timeout (timeout by default is 0.5s, can be configured with symbol-overlay-idle-time variable). If a word don't get highlighted, this means there's just one match on the screen (the one you put cursor upon), hence there's no need to highlight it.
It would be great if the highlights were permanent, i.e., moving point away from a highlighted word should not cause the highlight to be removed.
To highlight the word under cursor permanently there's a function symbol-overlay-put. To unhighlight call it once again.
In my config example it's bound to Logo+` key.
(require 'symbol-overlay)
(defun enable-symbol-overlay-mode ()
(unless (or (minibufferp)
(derived-mode-p 'magit-mode)
(derived-mode-p 'xref--xref-buffer-mode))
(symbol-overlay-mode t)))
(define-global-minor-mode global-symbol-overlay-mode ;; name of the new global mode
symbol-overlay-mode ;; name of the minor mode
enable-symbol-overlay-mode)
(global-symbol-overlay-mode) ;; enable it
(global-set-key (kbd "s-`") 'symbol-overlay-put)
(setq symbol-overlay-ignore-functions nil) ;; don't ignore keywords in various languages
(setq symbol-overlay-map (make-sparse-keymap)) ;; disable special cmds on overlays
This may not be as nice as what you were hoping but if you put
(global-hi-lock-mode 1)
in your .emacs file then you can type C-x w h REGEX <RET> <RET> to highlight all occurances of REGEX, and C-x w r REGEX <RET> to unhighlight them again. Again, not as elegant as you'd probably like, but it'll work.
Try http://www.emacswiki.org/emacs/msearch.el
All occurences of the text selected with the cursor are highlighted.
You have to drag over the string which you want to highlight. That enables you to easily change the selection without changing the highlight.
If you want to preserve the highlighting of a string you can freeze it.
You can enslave a buffer to another buffer. Text selected in the master buffer will also be highlighted in the slave buffer. That is useful for comparing buffers.
It is also useful for taking notes in one buffer while you investigate the text in another one. You can have a collection of keywords in the notes buffer. Drag over such a keyword and its occurences in the investigated text will be highlighted.
I am using this stuff for years now. I added the freezing quite recently. So, maybe something is broken. If this is the case leave me a note on http://www.emacswiki.org/emacs/msearch or here.
Check Interactive Highlighting
Should be:
C-x w h word <RET> <RET>
Try iedit. It highlights the word at point and lets you edit all occurrences of it easily. With an additional keystroke (C-'), it hides all the lines without that word in it. Very handy!
Commands in library highlight.el
let you (un)highlight text matching a regexp (in this case a symbol), using overlays or text properties. You can cycle among the occurrences. Highlighting can be temporary or persistent. (more info).
This maybe won't highlight but will search for a word without you needing to type it...
when you've reached the word you wanted to search, C-S, then read the full word with C-W then you can C-S and it will search for it. In my Emacs it also highlights all instances in the document.
This package available in Melpa works, you can customize the highlight style as well.
https://github.com/ignacy/idle-highlight-in-visible-buffers-mode