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