Mercurial > hg > xemacs-beta
comparison lisp/packages/underline.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Synched up with: FSF 19.30. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This package deals with the primitive form of underlining | |
29 ;; consisting of prefixing each character with "_\^h". The entry | |
30 ;; point `underline-region' performs such underlining on a region. | |
31 ;; The entry point `ununderline-region' removes it. | |
32 | |
33 ;;; Code: | |
34 | |
35 ;;;###autoload | |
36 (defun underline-region (start end) | |
37 "Underline all nonblank characters in the region. | |
38 Works by overstriking underscores. | |
39 Called from program, takes two arguments START and END | |
40 which specify the range to operate on." | |
41 (interactive "*r") | |
42 (save-excursion | |
43 (let ((end1 (make-marker))) | |
44 (move-marker end1 (max start end)) | |
45 (goto-char (min start end)) | |
46 (while (< (point) end1) | |
47 (or (looking-at "[_\^@- ]") | |
48 (insert "_\b")) | |
49 (forward-char 1))))) | |
50 | |
51 ;;;###autoload | |
52 (defun ununderline-region (start end) | |
53 "Remove all underlining (overstruck underscores) in the region. | |
54 Called from program, takes two arguments START and END | |
55 which specify the range to operate on." | |
56 (interactive "*r") | |
57 (save-excursion | |
58 (let ((end1 (make-marker))) | |
59 (move-marker end1 (max start end)) | |
60 (goto-char (min start end)) | |
61 (while (re-search-forward "_\b\\|\b_" end1 t) | |
62 (delete-char -2))))) | |
63 | |
64 ;;;###autoload | |
65 (defun unoverstrike-region (start end) | |
66 "Remove all overstriking (character-backspace-character) in the region. | |
67 Called from program, takes two arguments START and END which specify the | |
68 range to operate on." | |
69 (interactive "*r") | |
70 (save-excursion | |
71 (let ((end1 (make-marker))) | |
72 (move-marker end1 (max start end)) | |
73 (goto-char (min start end)) | |
74 (while (re-search-forward "\\(.\\)\b\\1" end1 t) | |
75 (delete-char -2))))) | |
76 | |
77 ;;;###autoload | |
78 (defun overstrike-region (start end) | |
79 "Overstrike (character-backspace-character) all nonblank characters in | |
80 the region. Called from program, takes two arguments START and END which | |
81 specify the range to operate on." | |
82 (interactive "*r") | |
83 (save-excursion | |
84 (let ((end1 (make-marker))) | |
85 (move-marker end1 (max start end)) | |
86 (goto-char (min start end)) | |
87 (while (< (point) end1) | |
88 (or (looking-at "[_\^@- ]") | |
89 (insert (char-after (point)) 8)) | |
90 (forward-char 1))))) | |
91 | |
92 ;;;###autoload | |
93 (defun ununderline-and-unoverstrike-region (start end) | |
94 "Remove underlining and overstriking in the region. Called from a program, | |
95 takes two arguments START and END which specify the range to operate on." | |
96 (interactive "*r") | |
97 (save-excursion | |
98 ;; This is a piece of nuke-nroff-bs from standard `man.el'. | |
99 (goto-char (point-min)) | |
100 (while (search-forward "\b" (max start end) t) | |
101 (let* ((preceding (char-after (- (point) 2))) | |
102 (following (following-char))) | |
103 (cond ((= preceding following) | |
104 ;; x\bx | |
105 (delete-char -2)) | |
106 ((= preceding ?\_) | |
107 ;; _\b | |
108 (delete-char -2)) | |
109 ((= following ?\_) | |
110 ;; \b_ | |
111 (delete-region (1- (point)) (1+ (point))))))))) | |
112 | |
113 ;;; underline.el ends here |