annotate lisp/delim-col.el @ 26581:b679911f6f28

*** empty log message ***
author Dave Love <fx@gnu.org>
date Wed, 24 Nov 1999 20:03:27 +0000
parents 8500b0f62b8e
children 001414add3a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; delim-col.el --- Prettify all columns in a region or rectangle.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
2
26040
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
4
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
26040
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
7 ;; Time-stamp: <99/08/21 19:51:13 vinicius>
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; Version: 1.3
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; Keywords: internal
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
10
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12
26040
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
16 ;; any later version.
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17
26040
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
21 ;; GNU General Public License for more details.
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22
26040
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
23 ;; You should have received a copy of the GNU General Public License
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8500b0f62b8e Header comments changed.
Dave Love <fx@gnu.org>
parents: 25761
diff changeset
26 ;; Boston, MA 02111-1307, USA.
25761
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
27
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
29
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; delim-col helps to prettify columns in a text region or rectangle.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; To use it, make sure that this file is in load-path and insert in your
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; .emacs:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
34 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;; (require 'delim-col)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;; If you have, for example, the following columns:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
38 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;; a b c d
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; aaaa bb ccc ddddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; aaa bbb cccc dddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
42 ;; aa bb ccccccc ddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
44 ;; And the following settings:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
45 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
46 ;; (setq delimit-columns-str-before "[ ")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
47 ;; (setq delimit-columns-str-after " ]")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
48 ;; (setq delimit-columns-str-separator ", ")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
49 ;; (setq delimit-columns-separator "\t")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
50 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
51 ;; If you select the lines above and type:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
52 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
53 ;; M-x delimit-columns-region RET
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
54 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
55 ;; You obtain the following result:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
56 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ;; [ a , b , c , d ]
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
58 ;; [ aaaa, bb , ccc , ddddd ]
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
59 ;; [ aaa , bbb, cccc , dddd ]
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
60 ;; [ aa , bb , ccccccc, ddd ]
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
61 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
62 ;; But if you select start from the very first b and the very last c and type:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
63 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
64 ;; M-x delimit-columns-rectangle RET
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
65 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
66 ;; You obtain the following result:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
67 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
68 ;; a [ b , c ] d
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
69 ;; aaaa [ bb , ccc ] ddddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
70 ;; aaa [ bbb, cccc ] dddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
71 ;; aa [ bb , ccccccc ] ddd
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
72 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
73 ;; Note that `delimit-columns-region' operates over all text region
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
74 ;; selected, extending the region start to the beginning of line and the
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
75 ;; region end to the end of line. While `delimit-columns-rectangle'
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
76 ;; operates over the text rectangle selected which rectangle diagonal is
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
77 ;; given by the region start and end.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
78 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
79 ;; `delimit-columns-region' is useful when you have columns of text that
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
80 ;; are not well aligned, like:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
81 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
82 ;; horse apple bus
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
83 ;; dog pineapple car
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
84 ;; porcupine strawberry airplane
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
85 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
86 ;; `delimit-columns-region' and `delimit-columns-rectangle' handle lines
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
87 ;; with different number of columns, like:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
88 ;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
89 ;; horse apple bus
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
90 ;; dog pineapple car EXTRA
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
91 ;; porcupine strawberry airplane
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
92
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
93 ;;; Code:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
94
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
95
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
97 ;; User Options:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
98
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
99 (defvar delimit-columns-str-before ""
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
100 "*Specify a string to be inserted before all columns.")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
101
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
102 (defvar delimit-columns-str-separator ", "
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
103 "*Specify a string to be inserted between each column.")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
104
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
105 (defvar delimit-columns-str-after ""
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
106 "*Specify a string to be inserted after all columns.")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
107
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
108 (defvar delimit-columns-separator "\t"
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
109 "*Specify a regexp which separates each column.")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
110
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
111
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
113 ;; User Commands:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
114
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
115
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
116 ;;;###autoload
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
117 (defun delimit-columns-region (start end)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
118 "Prettify all columns in a text region.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
119
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
120 START and END delimits the text region."
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
121 (interactive "*r")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (let ((delimit-columns-str-before
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
123 (if (stringp delimit-columns-str-before)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
124 delimit-columns-str-before
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
125 ""))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
126 (delimit-columns-str-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
127 (if (stringp delimit-columns-str-separator)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
128 delimit-columns-str-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
129 " "))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (delimit-columns-str-after
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
131 (if (stringp delimit-columns-str-after)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
132 delimit-columns-str-after
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
133 ""))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (delimit-columns-limit (make-marker))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (the-end (copy-marker end))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
136 delimit-columns-max)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
137 (save-excursion
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
138 (goto-char start)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
139 (beginning-of-line)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
140 ;; get maximum length for each column
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
141 (save-excursion
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
142 (while (< (point) the-end)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
143 (delimit-columns-rectangle-max
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
144 (prog1
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
145 (point)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
146 (end-of-line)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
147 (forward-char 1)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
148 ;; prettify columns
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
149 (while (< (point) the-end)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
150 (delimit-columns-rectangle-line
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
151 (prog1
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
152 (point)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
153 (end-of-line)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
154 (forward-char 1))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
155 ;; nullify markers
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
156 (set-marker delimit-columns-limit nil)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
157 (set-marker the-end nil))))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
158
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
159
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
160 (require 'rect)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
161
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
162
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
163 ;;;###autoload
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
164 (defun delimit-columns-rectangle (start end)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
165 "Prettify all columns in a text rectangle.
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
166
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
167 START and END delimits the corners of text rectangle."
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
168 (interactive "*r")
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
169 (let ((delimit-columns-str-before
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
170 (if (stringp delimit-columns-str-before)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
171 delimit-columns-str-before
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
172 ""))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
173 (delimit-columns-str-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
174 (if (stringp delimit-columns-str-separator)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
175 delimit-columns-str-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
176 " "))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
177 (delimit-columns-str-after
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
178 (if (stringp delimit-columns-str-after)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
179 delimit-columns-str-after
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
180 ""))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
181 (delimit-columns-limit (make-marker))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
182 (the-end (copy-marker end))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
183 delimit-columns-max)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
184 ;; get maximum length for each column
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
185 (save-excursion
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
186 (operate-on-rectangle 'delimit-columns-rectangle-max
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
187 start the-end t))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
188 ;; prettify columns
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
189 (save-excursion
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
190 (operate-on-rectangle 'delimit-columns-rectangle-line
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
191 start the-end t))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
192 ;; nullify markers
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (set-marker delimit-columns-limit nil)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
194 (set-marker the-end nil)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
195
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
196
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
198 ;; Internal Variables and Functions:
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
199
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
200
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
201 ;; to avoid compilation gripes
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
202 (defvar delimit-columns-max nil)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
203 (defvar delimit-columns-limit nil)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
204
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
205
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
206 (defun delimit-columns-rectangle-max (startpos &optional ignore ignore)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
207 (set-marker delimit-columns-limit (point))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
208 (goto-char startpos)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
209 (let ((ncol 1)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
210 origin values)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
211 ;; get current column length
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
212 (while (progn
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
213 (setq origin (current-column))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
214 (re-search-forward delimit-columns-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
215 delimit-columns-limit 'move))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
216 (save-excursion
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
217 (goto-char (match-beginning 0))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
218 (setq values (cons (- (current-column) origin)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
219 values)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
220 (setq ncol (1+ ncol)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
221 (setq values (cons (- (current-column) origin)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
222 values))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
223 ;; extend delimit-columns-max, if needed
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
224 (let ((index (length delimit-columns-max)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
225 (and (> ncol index)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
226 (let ((extend (make-vector ncol 0)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
227 (while (> index 0)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
228 (setq index (1- index))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
229 (aset extend index (aref delimit-columns-max index)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
230 (setq delimit-columns-max extend))))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
231 ;; get maximum column length
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
232 (while values
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
233 (setq ncol (1- ncol))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
234 (aset delimit-columns-max ncol (max (aref delimit-columns-max ncol)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
235 (car values)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
236 (setq values (cdr values)))))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
237
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
238
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
239 (defun delimit-columns-rectangle-line (startpos &optional ignore ignore)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
240 (let ((ncol 0)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
241 (len (length delimit-columns-max))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
242 origin)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
243 (set-marker delimit-columns-limit (point))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
244 (goto-char startpos)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
245 (insert delimit-columns-str-before)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
246 ;; Adjust all columns but last one
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
247 (while (progn
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
248 (setq origin (current-column))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
249 (and (< (point) delimit-columns-limit)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
250 (re-search-forward delimit-columns-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
251 delimit-columns-limit 'move)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
252 (delete-region (match-beginning 0) (point))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
253 (insert (make-string (- (aref delimit-columns-max ncol)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
254 (- (current-column) origin))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
255 ?\ )
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
256 delimit-columns-str-separator)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
257 (setq ncol (1+ ncol)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
258 ;; Adjust last column
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
259 (insert (make-string (- (aref delimit-columns-max ncol)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
260 (- (current-column) origin))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
261 ?\ ))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
262 ;; Adjust extra columns, if needed
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
263 (while (< (setq ncol (1+ ncol)) len)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
264 (insert delimit-columns-str-separator
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
265 (make-string (aref delimit-columns-max ncol) ?\ )))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
266 (insert delimit-columns-str-after)))
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
267
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
268
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
270
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
271
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
272 (provide 'delim-col)
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
273
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
274
605bd4f82d45 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
275 ;;; delim-col.el ends here