underline.el 2.1 KB
Newer Older
1
;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs  -*- lexical-binding: t -*-
Eric S. Raymond's avatar
Eric S. Raymond committed
2

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 1985, 2001-2019 Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
4

5
;; Maintainer: emacs-devel@gnu.org
Eric S. Raymond's avatar
Eric S. Raymond committed
6
;; Keywords: wp
Eric S. Raymond's avatar
Eric S. Raymond committed
7

Joseph Arceneaux's avatar
Joseph Arceneaux committed
8 9
;; This file is part of GNU Emacs.

10
;; GNU Emacs is free software: you can redistribute it and/or modify
Joseph Arceneaux's avatar
Joseph Arceneaux committed
11
;; it under the terms of the GNU General Public License as published by
12 13
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Joseph Arceneaux's avatar
Joseph Arceneaux committed
14 15 16 17 18 19 20

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; 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/>.
Joseph Arceneaux's avatar
Joseph Arceneaux committed
22

23 24 25 26 27 28 29
;;; Commentary:

;; This package deals with the primitive form of underlining
;; consisting of prefixing each character with "_\^h".  The entry
;; point `underline-region' performs such underlining on a region.
;; The entry point `ununderline-region' removes it.

Eric S. Raymond's avatar
Eric S. Raymond committed
30
;;; Code:
Joseph Arceneaux's avatar
Joseph Arceneaux committed
31

Jim Blandy's avatar
Jim Blandy committed
32
;;;###autoload
Joseph Arceneaux's avatar
Joseph Arceneaux committed
33 34 35 36 37
(defun underline-region (start end)
  "Underline all nonblank characters in the region.
Works by overstriking underscores.
Called from program, takes two arguments START and END
which specify the range to operate on."
38
  (interactive "*r")
Joseph Arceneaux's avatar
Joseph Arceneaux committed
39 40 41 42 43 44
  (save-excursion
   (let ((end1 (make-marker)))
     (move-marker end1 (max start end))
     (goto-char (min start end))
     (while (< (point) end1)
       (or (looking-at "[_\^@- ]")
45
	   (insert "_\b"))
Joseph Arceneaux's avatar
Joseph Arceneaux committed
46 47
       (forward-char 1)))))

Jim Blandy's avatar
Jim Blandy committed
48
;;;###autoload
Joseph Arceneaux's avatar
Joseph Arceneaux committed
49 50 51 52
(defun ununderline-region (start end)
  "Remove all underlining (overstruck underscores) in the region.
Called from program, takes two arguments START and END
which specify the range to operate on."
53
  (interactive "*r")
Joseph Arceneaux's avatar
Joseph Arceneaux committed
54 55 56 57
  (save-excursion
   (let ((end1 (make-marker)))
     (move-marker end1 (max start end))
     (goto-char (min start end))
58
     (while (re-search-forward "_\b\\|\b_" end1 t)
Joseph Arceneaux's avatar
Joseph Arceneaux committed
59
       (delete-char -2)))))
Eric S. Raymond's avatar
Eric S. Raymond committed
60

Richard M. Stallman's avatar
Richard M. Stallman committed
61 62
(provide 'underline)

Eric S. Raymond's avatar
Eric S. Raymond committed
63
;;; underline.el ends here