Home About me Blog Po polsku

Content AND Presentation

2014-09-27 show-paren-mode

For today, I only have a short tip. Sorry;-).

I guess many Emacs users know about show-paren-mode, which highlights the closing paren (or brace, or bracket…) when the point is on the opening one (or the opening one when the point is right after the closing one). BTW, one of the annoyances of show-paren-mode is that in this situation:


(the pipe symbol means the point), the closing brace after xyz is not highlighted (the opening one before abc is). Its a bit of a PITA for TeX users - yet another reason I’ll have to do some work on Emacs’ AUCTeX mode (though I’m not sure how to resolve this one). Some day.

OTOH, what is nice (and maybe less known) about show-paren-mode is its behavior when the matching paren is not visible. By default, nothing happens then, which is not that helpful. There is, however, a variable called show-paren-style, and setting it to 'mixed causes Emacs to highlight the matching paren if it’s visible and the whole visible part of the expression in parens when it’s not. Cool.

To sum it up, this is what I have in my init.el:

(setq show-paren-style 'mixed)

(Note that show-paren-mode is one of the rare examples of a global minor mode, so this turns it on basically everywhere.)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX

Komentarze na tej stronie

2014-09-20 Smart ties in Emacs

As all TeX users know, in all flavors of TeX you use the tilde (~), called a “tie” in The TeXbook, to denote non-breakable spaces. Of course, if you use Emacs, you may use some helpers, like tildify to insert them interactively or after typing/yanking some text. But what I sometimes do is yank some short fragments of text from various sources, or just forget to type a tie (though I trained myself to type them after e.g. all one-letter prepositions, which – according to Polish rules of typesetting – should not dangle at the end of the line by themselves). Then, I prefer to insert the tie by hand. The problem is, I had to delete the space and then press ~; two keystrokes instead of one. Blechhh. So I wrote this short piece of Elisp, and tied (pun intended) it to ~ (thanks to this answer on StackOverflow, I learned how to bind it using eval-after-load).

(defun electric-tie ()
  "Inserts a tilde at point unless the point is at a space
character(s), in which case it deletes the space(s) first."
  (while (equal (char-after) ?\s) (delete-char 1))
  (while (equal (char-before) ?\s) (delete-char -1))
  (call-interactively 'self-insert-command))

(eval-after-load 'tex '(define-key TeX-mode-map "~" 'electric-tie))

(Note: the quoted answer contains some suggestions of improving this code in terms of style. While I didn’t bother to do that, reading that answer is probably a good idea.)

CategoryEnglish, CategoryBlog, CategoryEmacs

Komentarze na tej stronie

2014-09-13 TeX input method

Some time ago, someone on the Emacs mailing list asked about entering a letter not present on a (typical) keyboard. There are a few ways to do it, some at the OS level and some on the editor level. The usual Emacs way is C-x 8 " o to get ö etc. (Incidentally, there seems to be no analogous command for œ, which was asked in that question! Also, I strongly recommend hitting C-x 8 C-h and at least skimming through the results, and checking out C-x 8 RET.) I was a bit surprised, though, that nobody mentioned the TeX input method. Input methods are Emacs’ ways of entering “complicated” characters. (Many of them are designed to enter Chinese, Japanese or Korean languages.) In my setup, I have the TeX input method as the default (this can be achieved e.g. by putting (setq default-input-method "TeX") in your init.el). (Normally, you don’t have any input method turned on; C-\ toggles between no input method and your default one, and C-x RET C-\ sets the default one.) Now, typing \"o instead of C-x 8 " o is a small (but noticeable) gain. The real strength of the TeX input method is in typing math symbols. Try it yourself: not only \alpha (α), \beta (β) and other Greek letters work, but also all the Unicode goodness like \int (∫), \infty (∞), \in (∈), \subset (⊂), \aleph (ℵ), \heartsuit (♥) and lots of other ones. (Also, some sub- and superscripts work, like \aleph_0 (ℵ₀) or \pi r^2 (π r²).)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX

Komentarze na tej stronie


(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog