File: underline.el

package info (click to toggle)
xemacs21-packages 2009.02.17.dfsg.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 116,928 kB
  • ctags: 88,975
  • sloc: lisp: 1,232,060; ansic: 16,570; java: 13,514; xml: 6,477; sh: 4,611; makefile: 4,036; asm: 3,007; perl: 839; cpp: 500; ruby: 257; csh: 96; haskell: 93; awk: 49; python: 47
file content (118 lines) | stat: -rw-r--r-- 3,996 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs.

;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.

;; Maintainer: FSF
;; Keywords: wp

;; This file is part of XEmacs.

;; XEmacs is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; XEmacs 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
;; along with XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with: FSF 19.34.

;;; 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.

;;; Code:

;;;###autoload
(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."
  ;; XEmacs: FSF doesn't use a '*', a bug?  -sb
  (interactive "*r")
  (save-excursion
    (let ((end1 (make-marker)))
      (move-marker end1 (max start end))
      (goto-char (min start end))
      (while (< (point) end1)
	(or (looking-at "[_\^@- ]")
	    (insert "_\b"))
	(forward-char 1)))))

;;;###autoload
(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."
  (interactive "*r")
  (save-excursion
    (let ((end1 (make-marker)))
      (move-marker end1 (max start end))
      (goto-char (min start end))
      (while (re-search-forward "_\b\\|\b_" end1 t)
	(delete-char -2)))))

;; XEmacs:  The rest of these functions are not in FSF.  I don't see any
;; point in removing them.  -sb

;;;###autoload
(defun unoverstrike-region (start end)
  "Remove all overstriking (character-backspace-character) in the region.
Called from program, takes two arguments START and END which specify the
range to operate on."
  (interactive "*r")
  (save-excursion
    (let ((end1 (make-marker)))
      (move-marker end1 (max start end))
      (goto-char (min start end))
      (while (re-search-forward "\\(.\\)\b\\1" end1 t)
	(delete-char -2)))))

;;;###autoload
(defun overstrike-region (start end)
  "Overstrike (character-backspace-character) all nonblank characters in
the region. Called from program, takes two arguments START and END which
specify the range to operate on."
  (interactive "*r")
  (save-excursion
    (let ((end1 (make-marker)))
      (move-marker end1 (max start end))
      (goto-char (min start end))
      (while (< (point) end1)
	(or (looking-at "[_\^@- ]")
	    (insert (char-after (point)) 8))
	(forward-char 1)))))

;;;###autoload
(defun ununderline-and-unoverstrike-region (start end)
  "Remove underlining and overstriking in the region.  Called from a program,
takes two arguments START and END which specify the range to operate on."
  (interactive "*r")
  (save-excursion
    ;; This is a piece of nuke-nroff-bs from standard `man.el'.
    (goto-char (point-min))
    (while (search-forward "\b" (max start end) t)
      (let* ((preceding (char-after (- (point) 2)))
	     (following (following-char)))
	(cond ((= preceding following)
	       ;; x\bx
	       (delete-char -2))
	      ((= preceding ?\_)
	       ;; _\b
	       (delete-char -2))
	      ((= following ?\_)
	       ;; \b_
	       (delete-region (1- (point)) (1+ (point)))))))))

;;; underline.el ends here