0
|
1 ;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs.
|
|
2
|
|
3 ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6 ;; Keywords: wp
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
0
|
24
|
2
|
25 ;;; Synched up with: FSF 19.34.
|
0
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This package deals with the primitive form of underlining
|
|
30 ;; consisting of prefixing each character with "_\^h". The entry
|
|
31 ;; point `underline-region' performs such underlining on a region.
|
|
32 ;; The entry point `ununderline-region' removes it.
|
|
33
|
|
34 ;;; Code:
|
|
35
|
|
36 ;;;###autoload
|
|
37 (defun underline-region (start end)
|
|
38 "Underline all nonblank characters in the region.
|
|
39 Works by overstriking underscores.
|
|
40 Called from program, takes two arguments START and END
|
|
41 which specify the range to operate on."
|
2
|
42 ;; XEmacs: FSF doesn't use a '*', a bug? -sb
|
0
|
43 (interactive "*r")
|
|
44 (save-excursion
|
|
45 (let ((end1 (make-marker)))
|
|
46 (move-marker end1 (max start end))
|
|
47 (goto-char (min start end))
|
|
48 (while (< (point) end1)
|
|
49 (or (looking-at "[_\^@- ]")
|
|
50 (insert "_\b"))
|
|
51 (forward-char 1)))))
|
|
52
|
|
53 ;;;###autoload
|
|
54 (defun ununderline-region (start end)
|
|
55 "Remove all underlining (overstruck underscores) in the region.
|
|
56 Called from program, takes two arguments START and END
|
|
57 which specify the range to operate on."
|
|
58 (interactive "*r")
|
|
59 (save-excursion
|
|
60 (let ((end1 (make-marker)))
|
|
61 (move-marker end1 (max start end))
|
|
62 (goto-char (min start end))
|
|
63 (while (re-search-forward "_\b\\|\b_" end1 t)
|
|
64 (delete-char -2)))))
|
|
65
|
2
|
66 ;; XEmacs: The rest of these functions are not in FSF. I don't see any
|
|
67 ;; point in removing them. -sb
|
|
68
|
0
|
69 ;;;###autoload
|
|
70 (defun unoverstrike-region (start end)
|
|
71 "Remove all overstriking (character-backspace-character) in the region.
|
|
72 Called from program, takes two arguments START and END which specify the
|
|
73 range to operate on."
|
|
74 (interactive "*r")
|
|
75 (save-excursion
|
|
76 (let ((end1 (make-marker)))
|
|
77 (move-marker end1 (max start end))
|
|
78 (goto-char (min start end))
|
|
79 (while (re-search-forward "\\(.\\)\b\\1" end1 t)
|
|
80 (delete-char -2)))))
|
|
81
|
|
82 ;;;###autoload
|
|
83 (defun overstrike-region (start end)
|
|
84 "Overstrike (character-backspace-character) all nonblank characters in
|
|
85 the region. Called from program, takes two arguments START and END which
|
|
86 specify the range to operate on."
|
|
87 (interactive "*r")
|
|
88 (save-excursion
|
|
89 (let ((end1 (make-marker)))
|
|
90 (move-marker end1 (max start end))
|
|
91 (goto-char (min start end))
|
|
92 (while (< (point) end1)
|
|
93 (or (looking-at "[_\^@- ]")
|
|
94 (insert (char-after (point)) 8))
|
|
95 (forward-char 1)))))
|
|
96
|
|
97 ;;;###autoload
|
|
98 (defun ununderline-and-unoverstrike-region (start end)
|
|
99 "Remove underlining and overstriking in the region. Called from a program,
|
|
100 takes two arguments START and END which specify the range to operate on."
|
|
101 (interactive "*r")
|
|
102 (save-excursion
|
|
103 ;; This is a piece of nuke-nroff-bs from standard `man.el'.
|
|
104 (goto-char (point-min))
|
|
105 (while (search-forward "\b" (max start end) t)
|
|
106 (let* ((preceding (char-after (- (point) 2)))
|
|
107 (following (following-char)))
|
|
108 (cond ((= preceding following)
|
|
109 ;; x\bx
|
|
110 (delete-char -2))
|
|
111 ((= preceding ?\_)
|
|
112 ;; _\b
|
|
113 (delete-char -2))
|
|
114 ((= following ?\_)
|
|
115 ;; \b_
|
|
116 (delete-region (1- (point)) (1+ (point)))))))))
|
|
117
|
|
118 ;;; underline.el ends here
|