Emacs highlight specific words when opening - emacs

I can use M-x highlight-phrase when I am in the editor. But I want to see the phrase ERROR highlighted in red when I open any file that contains that phrase.
I still cannot figure out how to enable this on my init.el file. Any help?
Thanks in advance

There are existing modes for this sort of thing.
See http://www.emacswiki.org/emacs/FixmeMode
From the looks of it, the best version is likely to be this:
https://github.com/lewang/fic-mode

This looks gruesome to me but if you really want it:
(add-hook 'find-file-hook (lambda () (highlight-regexp "\\<ERROR\\>")))

Related

Customize emacs space indentation

I have to adjust to 4 space indentation for a project I'm collaborating on at work. I hate looking at it, being accustomed to a nice compact 2 space indentation. Is there any way to have emacs display 2 spaces as one? Or maybe tabify on file load, and untabify on save. I'm working in c++. I have searched through google, but can't seem to find an answer to this.
You can try using prettify-symbols-mode, which is built into Emacs >=24.5.
(defun jpk/contract-spaces ()
(add-to-list 'prettify-symbols-alist '(" " . ?\ ))
(prettify-symbols-mode 1))
(add-hook 'c-mode-common-hook 'jpk/c-contract-spaces)
This changes the display, not the content of the buffer or file. I'm not sure this is the best idea. It will affect (auto)indentation and you won't see what the saved file will look like.

Emacs - Toggling between Visual Markers?

I'm trying to figure out if this functionality exists, or if not how difficult it would be to program.
Essentially what I'm looking for is the ability to mark multiple lines in a file with some form of highlighting to point out that they're important lines. From there on it would be great to be able to toggle on/off the marker, and be able to toggle through them - for larger files it would be great to be able to do this for important lines.
The markers don't have to persist, just for that session would be great.
I took a look into the "Overview of Markers" page - but I'm not sure this is exactly what I want, and if it's worth the time to try and implement it if it's not.
Thanks for any/all help!
It looks like bm.el does exactly what you want.
You want quick, perhaps temporary bookmarks that highlight the location (e.g. line): Bookmark+.
Autonamed bookmarks: hit the same key to create/delete.
Temporary bookmarks: any bookmarks can be temporary; quick to toggle temp/permanent.
Highlighting bookmark locations: any bookmarks can be highlighted, in various ways.
FWIW, Bookmark+ does everything bm.el does, and more.
This is somewhat similar to what highlight-regexp does, except arbitrary text instead of a regexp. Based on that, I think something like this should work:
(defun highlight-text ()
"Highlight the current region."
(interactive)
(let ((overlay (make-overlay (region-beginning) (region-end))))
(overlay-put overlay 'face 'hi-yellow)))

How can I get emacs to show line numbers when the 'text-mode-hook appears not to be working?

I am trying to use setnu.el to give me line numbers in emacs, which as you might imagine I want in pretty much every mode. It seemed like the preffered way of doing this in Emacs is to use
(add-hook 'text-mode-hook 'turn-on-setnu-mode)
but this isn't working for me. Using
(add-hook 'emacs-lisp-mode-hook 'turn-on-setnu-mode)
works just fine when I am editing emacs lisp files, but I want line numbers in all my text viewing and don't want to have a special case for each kind of file in my init.d file. Help would be much appreciated.
Linum seems to be distributed with emacs >=22.
Try:
(require 'linum)
Then toggle the display of line numbers with
M-x linum-mode
http://web.student.tuwien.ac.at/~e0225855/linum/linum.html

Emacs - how do I automatically enter minor modes when I enter a major mode?

I'm kind of a newb when it comes to emacs. I know about the .emacs file but have very little idea as to do anything more advanced than elementary stuff.
Whenever I enter latex-mode, I'd also like to automatically turn on flyspell-mode, reftex-mode, auto-fill-mode, and also set fill-column to 120. How do I edit my .emacs file to do this?
Thanks!
(add-hook 'latex-mode-hook
(function (lambda ()
(flymake-mode)
(reftex-mode)
(auto-fill-mode)
(setq fill-column 120))))
for example should work.
You can set a so-called hook to a major mode. Have a look at this page of the manual for some examples.

emacs auctex: can one auto-fill section labels?

I am currently using emacs and auctex to author my latex documents. This is, of course, fantastic. However, I would like to have emacs and/or auctex auto-fill the section label when using C-c C-e to make a new header. It should end up looking like this:
\section{This is a section title}
\label{sec:this-is-a-section-title}
with the label for the header the same as the title, but with no spaces. I don't know lisp or elisp, and I'd have no idea where to start. If anyone could help that would be great!
If you use RefTeX then C-c ( will do what you want (giving you the opportunity to change the label if you wish). Also C-c ) will insert \ref{...}, popping up a buffer to choose which label to use. It also does other stuff including working with bibliographies. You should definitely look into it.
I think it's now part of the AUCTeX distribution so that all you should have to do is add
(add-hook 'LaTeX-mode-hook (function turn-on-reftex))
(setq reftex-plug-into-AUCTeX t)
to your .emacs.