Merge from emacs-23
[bpt/emacs.git] / lisp / textmodes / underline.el
CommitLineData
55535639 1;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs
d501f516 2
f2e3589a 3;; Copyright (C) 1985, 2001, 2002, 2003, 2004, 2005,
5df4f04c 4;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
58142744 5
e5167999 6;; Maintainer: FSF
d7b4d18f 7;; Keywords: wp
e5167999 8
a2535589
JA
9;; This file is part of GNU Emacs.
10
1fecc8fe 11;; GNU Emacs is free software: you can redistribute it and/or modify
a2535589 12;; it under the terms of the GNU General Public License as published by
1fecc8fe
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
a2535589
JA
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
1fecc8fe 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a2535589 23
c91c4e6d
ER
24;;; Commentary:
25
26;; This package deals with the primitive form of underlining
27;; consisting of prefixing each character with "_\^h". The entry
28;; point `underline-region' performs such underlining on a region.
29;; The entry point `ununderline-region' removes it.
30
e5167999 31;;; Code:
a2535589 32
f9f9507e 33;;;###autoload
a2535589
JA
34(defun underline-region (start end)
35 "Underline all nonblank characters in the region.
36Works by overstriking underscores.
37Called from program, takes two arguments START and END
38which specify the range to operate on."
8371c2f2 39 (interactive "*r")
a2535589
JA
40 (save-excursion
41 (let ((end1 (make-marker)))
42 (move-marker end1 (max start end))
43 (goto-char (min start end))
44 (while (< (point) end1)
45 (or (looking-at "[_\^@- ]")
af282089 46 (insert "_\b"))
a2535589
JA
47 (forward-char 1)))))
48
f9f9507e 49;;;###autoload
a2535589
JA
50(defun ununderline-region (start end)
51 "Remove all underlining (overstruck underscores) in the region.
52Called from program, takes two arguments START and END
53which specify the range to operate on."
8371c2f2 54 (interactive "*r")
a2535589
JA
55 (save-excursion
56 (let ((end1 (make-marker)))
57 (move-marker end1 (max start end))
58 (goto-char (min start end))
af282089 59 (while (re-search-forward "_\b\\|\b_" end1 t)
a2535589 60 (delete-char -2)))))
d501f516 61
896546cd
RS
62(provide 'underline)
63
cbee283d 64;; arch-tag: e7b48582-c3ea-4386-987a-87415f3c372a
d501f516 65;;; underline.el ends here