Mercurial > emacs
annotate lisp/delim-col.el @ 73987:e894b4d1b811
*** empty log message ***
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Tue, 14 Nov 2006 06:30:50 +0000 |
parents | c801be549845 |
children | 8c9e156de392 bb0e318b7c53 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33092
diff
changeset
|
1 ;;; delim-col.el --- prettify all columns in a region or rectangle |
25761 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64762
diff
changeset
|
4 ;; 2005, 2006 Free Software Foundation, Inc. |
25761 | 5 |
54326 | 6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> | |
73026
c801be549845
Adjust X-URL
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
68651
diff
changeset
|
8 ;; Time-stamp: <2006/09/15 17:35:06 vinicius> |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33092
diff
changeset
|
9 ;; Version: 2.1 |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33092
diff
changeset
|
10 ;; Keywords: internal |
73026
c801be549845
Adjust X-URL
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
68651
diff
changeset
|
11 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre |
25761 | 12 |
13 ;; This file is part of GNU Emacs. | |
14 | |
26040 | 15 ;; GNU Emacs is free software; you can redistribute it and/or modify |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
25761 | 19 |
26040 | 20 ;; GNU Emacs is distributed in the hope that it will be useful, |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
25761 | 24 |
26040 | 25 ;; You should have received a copy of the GNU General Public License |
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
28 ;; Boston, MA 02110-1301, USA. | |
25761 | 29 |
30 ;;; Commentary: | |
31 | |
32 ;; delim-col helps to prettify columns in a text region or rectangle. | |
33 ;; | |
34 ;; To use it, make sure that this file is in load-path and insert in your | |
35 ;; .emacs: | |
36 ;; | |
37 ;; (require 'delim-col) | |
38 ;; | |
39 ;; If you have, for example, the following columns: | |
40 ;; | |
41 ;; a b c d | |
42 ;; aaaa bb ccc ddddd | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
43 ;; aaa bbb cccc dddd |
25761 | 44 ;; aa bb ccccccc ddd |
45 ;; | |
46 ;; And the following settings: | |
47 ;; | |
48 ;; (setq delimit-columns-str-before "[ ") | |
49 ;; (setq delimit-columns-str-after " ]") | |
50 ;; (setq delimit-columns-str-separator ", ") | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
51 ;; (setq delimit-columns-before "") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
52 ;; (setq delimit-columns-after "") |
25761 | 53 ;; (setq delimit-columns-separator "\t") |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
54 ;; (setq delimit-columns-format 'separator) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
55 ;; (setq delimit-columns-extra t) |
25761 | 56 ;; |
57 ;; If you select the lines above and type: | |
58 ;; | |
59 ;; M-x delimit-columns-region RET | |
60 ;; | |
61 ;; You obtain the following result: | |
62 ;; | |
63 ;; [ a , b , c , d ] | |
64 ;; [ aaaa, bb , ccc , ddddd ] | |
65 ;; [ aaa , bbb, cccc , dddd ] | |
66 ;; [ aa , bb , ccccccc, ddd ] | |
67 ;; | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
68 ;; But if you select start from the very first b to the very last c and type: |
25761 | 69 ;; |
70 ;; M-x delimit-columns-rectangle RET | |
71 ;; | |
72 ;; You obtain the following result: | |
73 ;; | |
74 ;; a [ b , c ] d | |
75 ;; aaaa [ bb , ccc ] ddddd | |
76 ;; aaa [ bbb, cccc ] dddd | |
77 ;; aa [ bb , ccccccc ] ddd | |
78 ;; | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
79 ;; Now, if we change settings to: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
80 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
81 ;; (setq delimit-columns-before "<") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
82 ;; (setq delimit-columns-after ">") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
83 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
84 ;; For the `delimit-columns-region' example above, the result is: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
85 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
86 ;; [ <a> , <b> , <c> , <d> ] |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
87 ;; [ <aaaa>, <bb> , <ccc> , <ddddd> ] |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
88 ;; [ <aaa> , <bbb>, <cccc> , <dddd> ] |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
89 ;; [ <aa> , <bb> , <ccccccc>, <ddd> ] |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
90 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
91 ;; And for the `delimit-columns-rectangle' example above, the result is: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
92 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
93 ;; a [ <b> , <c> ] d |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
94 ;; aaaa [ <bb> , <ccc> ] ddddd |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
95 ;; aaa [ <bbb>, <cccc> ] dddd |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
96 ;; aa [ <bb> , <ccccccc> ] ddd |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
97 ;; |
25761 | 98 ;; Note that `delimit-columns-region' operates over all text region |
99 ;; selected, extending the region start to the beginning of line and the | |
100 ;; region end to the end of line. While `delimit-columns-rectangle' | |
101 ;; operates over the text rectangle selected which rectangle diagonal is | |
102 ;; given by the region start and end. | |
103 ;; | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
104 ;; See `delimit-columns-format' variable documentation for column formating. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
105 ;; |
25761 | 106 ;; `delimit-columns-region' is useful when you have columns of text that |
107 ;; are not well aligned, like: | |
108 ;; | |
109 ;; horse apple bus | |
110 ;; dog pineapple car | |
111 ;; porcupine strawberry airplane | |
112 ;; | |
113 ;; `delimit-columns-region' and `delimit-columns-rectangle' handle lines | |
114 ;; with different number of columns, like: | |
115 ;; | |
116 ;; horse apple bus | |
117 ;; dog pineapple car EXTRA | |
118 ;; porcupine strawberry airplane | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
119 ;; |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
120 ;; Use `delimit-columns-customize' to customize delim-col package variables. |
25761 | 121 |
122 ;;; Code: | |
123 | |
124 | |
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
126 ;; User Options: | |
127 | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
128 (defgroup columns nil |
64003
bf6ae7cf12eb
(columns): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
54326
diff
changeset
|
129 "Prettify columns." |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
130 :link '(emacs-library-link :tag "Source Lisp File" "delim-col.el") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
131 :prefix "delimit-columns-" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
132 :group 'internal) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
133 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
134 (defcustom delimit-columns-str-before "" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
135 "*Specify a string to be inserted before all columns." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
136 :type '(string :tag "Before All Columns") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
137 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
138 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
139 (defcustom delimit-columns-str-separator ", " |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
140 "*Specify a string to be inserted between each column." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
141 :type '(string :tag "Between Each Column") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
142 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
143 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
144 (defcustom delimit-columns-str-after "" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
145 "*Specify a string to be inserted after all columns." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
146 :type '(string :tag "After All Columns") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
147 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
148 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
149 (defcustom delimit-columns-before "" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
150 "*Specify a string to be inserted before each column." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
151 :type '(string :tag "Before Each Column") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
152 :group 'columns) |
25761 | 153 |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
154 (defcustom delimit-columns-after "" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
155 "*Specify a string to be inserted after each column." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
156 :type '(string :tag "After Each Column") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
157 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
158 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
159 (defcustom delimit-columns-separator "\t" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
160 "*Specify a regexp which separates each column." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
161 :type '(regexp :tag "Column Separator") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
162 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
163 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
164 (defcustom delimit-columns-format t |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
165 "*Specify how to format columns. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
166 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
167 For examples below, consider: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
168 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
169 + columns `ccc' and `dddd', |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
170 + the maximum column length for each column is 6, |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
171 + and the following settings: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
172 (setq delimit-columns-before \"<\") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
173 (setq delimit-columns-after \">\") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
174 (setq delimit-columns-separator \":\") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
175 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
176 Valid values are: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
177 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
178 nil no formating. That is, `delimit-columns-after' is followed by |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
179 `delimit-columns-separator'. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
180 For example, the result is: \"<ccc>:<dddd>:\" |
25761 | 181 |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
182 t align columns. That is, `delimit-columns-after' is followed by |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
183 `delimit-columns-separator' and then followed by spaces. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
184 For example, the result is: \"<ccc>: <dddd>: \" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
185 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
186 'separator align separators. That is, `delimit-columns-after' is followed |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
187 by spaces and then followed by `delimit-columns-separator'. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
188 For example, the result is: \"<ccc> :<dddd> :\" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
189 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
190 'padding format column by filling with spaces before |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
191 `delimit-columns-after'. That is, spaces are followed by |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
192 `delimit-columns-after' and then followed by |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
193 `delimit-columns-separator'. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
194 For example, the result is: \"<ccc >:<dddd >:\" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
195 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
196 Any other value is treated as t." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
197 :type '(choice :menu-tag "Column Formating" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
198 :tag "Column Formating" |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
199 (const :tag "No Formating" nil) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
200 (const :tag "Column Alignment" t) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
201 (const :tag "Separator Aligment" separator) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
202 (const :tag "Column Padding" padding)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
203 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
204 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
205 (defcustom delimit-columns-extra t |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
206 "*Non-nil means that lines will have the same number of columns. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
207 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
208 This has effect only when there are lines with different number of columns." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
209 :type '(boolean :tag "Lines With Same Number Of Column") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
210 :group 'columns) |
25761 | 211 |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
212 (defcustom delimit-columns-start 0 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
213 "*Specify column number to start prettifing. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
214 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
215 See also `delimit-columns-end' for documentation. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
216 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
217 The following relation must hold: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
218 0 <= delimit-columns-start <= delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
219 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
220 The column number start from 0 and it's relative to the beginning of selected |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
221 region. So if you selected a text region, the first column (column 0) is |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
222 located at beginning of line. If you selected a text rectangle, the first |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
223 column (column 0) is located at left corner." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
224 :type '(integer :tag "Column Start") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
225 :group 'columns) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
226 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
227 (defcustom delimit-columns-end 1000000 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
228 "*Specify column number to end prettifing. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
229 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
230 See also `delimit-columns-start' for documentation. |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
231 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
232 The following relation must hold: |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
233 0 <= delimit-columns-start <= delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
234 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
235 The column number start from 0 and it's relative to the beginning of selected |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
236 region. So if you selected a text region, the first column (column 0) is |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
237 located at beginning of line. If you selected a text rectangle, the first |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
238 column (column 0) is located at left corner." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
239 :type '(integer :tag "Column End") |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
240 :group 'columns) |
25761 | 241 |
242 | |
243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
244 ;; User Commands: | |
245 | |
246 | |
247 ;;;###autoload | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
248 (defun delimit-columns-customize () |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
249 "Customization of `columns' group." |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
250 (interactive) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
251 (customize-group 'columns)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
252 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
253 |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
254 (defmacro delimit-columns-str (str) |
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
255 `(if (stringp ,str) ,str "")) |
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
256 |
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
257 |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
258 ;;;###autoload |
25761 | 259 (defun delimit-columns-region (start end) |
260 "Prettify all columns in a text region. | |
261 | |
262 START and END delimits the text region." | |
263 (interactive "*r") | |
264 (let ((delimit-columns-str-before | |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
265 (delimit-columns-str delimit-columns-str-before)) |
25761 | 266 (delimit-columns-str-separator |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
267 (delimit-columns-str delimit-columns-str-separator)) |
25761 | 268 (delimit-columns-str-after |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
269 (delimit-columns-str delimit-columns-str-after)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
270 (delimit-columns-before |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
271 (delimit-columns-str delimit-columns-before)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
272 (delimit-columns-after |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
273 (delimit-columns-str delimit-columns-after)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
274 (delimit-columns-start |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
275 (if (and (integerp delimit-columns-start) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
276 (>= delimit-columns-start 0)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
277 delimit-columns-start |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
278 0)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
279 (delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
280 (if (integerp delimit-columns-end) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
281 delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
282 1000000)) |
25761 | 283 (delimit-columns-limit (make-marker)) |
284 (the-end (copy-marker end)) | |
285 delimit-columns-max) | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
286 (when (<= delimit-columns-start delimit-columns-end) |
25761 | 287 (save-excursion |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
288 (goto-char start) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
289 (beginning-of-line) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
290 ;; get maximum length for each column |
33056
6566390db905
Little fix: replace delimit-columns-align-columns by
Gerd Moellmann <gerd@gnu.org>
parents:
32835
diff
changeset
|
291 (and delimit-columns-format |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
292 (save-excursion |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
293 (while (< (point) the-end) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
294 (delimit-columns-rectangle-max |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
295 (prog1 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
296 (point) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
297 (end-of-line))) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
298 (forward-char 1)))) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
299 ;; prettify columns |
25761 | 300 (while (< (point) the-end) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
301 (delimit-columns-rectangle-line |
25761 | 302 (prog1 |
303 (point) | |
304 (end-of-line))) | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
305 (forward-char 1)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
306 ;; nullify markers |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
307 (set-marker delimit-columns-limit nil) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
308 (set-marker the-end nil))))) |
25761 | 309 |
310 | |
311 (require 'rect) | |
312 | |
313 | |
314 ;;;###autoload | |
315 (defun delimit-columns-rectangle (start end) | |
316 "Prettify all columns in a text rectangle. | |
317 | |
318 START and END delimits the corners of text rectangle." | |
319 (interactive "*r") | |
320 (let ((delimit-columns-str-before | |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
321 (delimit-columns-str delimit-columns-str-before)) |
25761 | 322 (delimit-columns-str-separator |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
323 (delimit-columns-str delimit-columns-str-separator)) |
25761 | 324 (delimit-columns-str-after |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
325 (delimit-columns-str delimit-columns-str-after)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
326 (delimit-columns-before |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
327 (delimit-columns-str delimit-columns-before)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
328 (delimit-columns-after |
33092
181e948ec3ac
Little programming improvement.
Gerd Moellmann <gerd@gnu.org>
parents:
33056
diff
changeset
|
329 (delimit-columns-str delimit-columns-after)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
330 (delimit-columns-start |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
331 (if (and (integerp delimit-columns-start) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
332 (>= delimit-columns-start 0)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
333 delimit-columns-start |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
334 0)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
335 (delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
336 (if (integerp delimit-columns-end) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
337 delimit-columns-end |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
338 1000000)) |
25761 | 339 (delimit-columns-limit (make-marker)) |
340 (the-end (copy-marker end)) | |
341 delimit-columns-max) | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
342 (when (<= delimit-columns-start delimit-columns-end) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
343 ;; get maximum length for each column |
33056
6566390db905
Little fix: replace delimit-columns-align-columns by
Gerd Moellmann <gerd@gnu.org>
parents:
32835
diff
changeset
|
344 (and delimit-columns-format |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
345 (save-excursion |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
346 (operate-on-rectangle 'delimit-columns-rectangle-max |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
347 start the-end nil))) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
348 ;; prettify columns |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
349 (save-excursion |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
350 (operate-on-rectangle 'delimit-columns-rectangle-line |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
351 start the-end nil)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
352 ;; nullify markers |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
353 (set-marker delimit-columns-limit nil) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
354 (set-marker the-end nil)))) |
25761 | 355 |
356 | |
357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
358 ;; Internal Variables and Functions: | |
359 | |
360 | |
361 ;; to avoid compilation gripes | |
362 (defvar delimit-columns-max nil) | |
363 (defvar delimit-columns-limit nil) | |
364 | |
365 | |
39867
e4e8b9d662e2
(delimit-columns-rectangle-max): Do not double variables in the lambda-list.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
366 (defun delimit-columns-rectangle-max (startpos &optional ignore1 ignore2) |
25761 | 367 (set-marker delimit-columns-limit (point)) |
368 (goto-char startpos) | |
369 (let ((ncol 1) | |
370 origin values) | |
371 ;; get current column length | |
372 (while (progn | |
373 (setq origin (current-column)) | |
374 (re-search-forward delimit-columns-separator | |
375 delimit-columns-limit 'move)) | |
376 (save-excursion | |
377 (goto-char (match-beginning 0)) | |
378 (setq values (cons (- (current-column) origin) | |
379 values))) | |
380 (setq ncol (1+ ncol))) | |
381 (setq values (cons (- (current-column) origin) | |
382 values)) | |
383 ;; extend delimit-columns-max, if needed | |
384 (let ((index (length delimit-columns-max))) | |
385 (and (> ncol index) | |
386 (let ((extend (make-vector ncol 0))) | |
387 (while (> index 0) | |
388 (setq index (1- index)) | |
389 (aset extend index (aref delimit-columns-max index))) | |
390 (setq delimit-columns-max extend)))) | |
391 ;; get maximum column length | |
392 (while values | |
393 (setq ncol (1- ncol)) | |
394 (aset delimit-columns-max ncol (max (aref delimit-columns-max ncol) | |
395 (car values))) | |
396 (setq values (cdr values))))) | |
397 | |
398 | |
39867
e4e8b9d662e2
(delimit-columns-rectangle-max): Do not double variables in the lambda-list.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
399 (defun delimit-columns-rectangle-line (startpos &optional ignore1 ignore2) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
400 (let ((len (length delimit-columns-max)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
401 (ncol 0) |
25761 | 402 origin) |
403 (set-marker delimit-columns-limit (point)) | |
404 (goto-char startpos) | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
405 ;; skip initial columns |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
406 (while (and (< ncol delimit-columns-start) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
407 (< (point) delimit-columns-limit) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
408 (re-search-forward delimit-columns-separator |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
409 delimit-columns-limit 'move)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
410 (setq ncol (1+ ncol))) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
411 ;; insert first formating |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
412 (insert delimit-columns-str-before delimit-columns-before) |
25761 | 413 ;; Adjust all columns but last one |
414 (while (progn | |
415 (setq origin (current-column)) | |
416 (and (< (point) delimit-columns-limit) | |
417 (re-search-forward delimit-columns-separator | |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
418 delimit-columns-limit 'move) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
419 (or (< ncol delimit-columns-end) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
420 (progn |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
421 (goto-char (match-beginning 0)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
422 nil)))) |
25761 | 423 (delete-region (match-beginning 0) (point)) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
424 (delimit-columns-format |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
425 (and delimit-columns-format |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
426 (make-string (- (aref delimit-columns-max ncol) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
427 (- (current-column) origin)) |
64003
bf6ae7cf12eb
(columns): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
54326
diff
changeset
|
428 ?\s))) |
25761 | 429 (setq ncol (1+ ncol))) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
430 ;; Prepare last column spaces |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
431 (let ((spaces (and delimit-columns-format |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
432 (make-string (- (aref delimit-columns-max ncol) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
433 (- (current-column) origin)) |
64003
bf6ae7cf12eb
(columns): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
54326
diff
changeset
|
434 ?\s)))) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
435 ;; Adjust extra columns, if needed |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
436 (and delimit-columns-extra |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
437 (while (and (< (setq ncol (1+ ncol)) len) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
438 (<= ncol delimit-columns-end)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
439 (delimit-columns-format spaces) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
440 (setq spaces (and delimit-columns-format |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
441 (make-string (aref delimit-columns-max ncol) |
64003
bf6ae7cf12eb
(columns): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
54326
diff
changeset
|
442 ?\s))))) |
32835
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
443 ;; insert last formating |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
444 (cond ((null delimit-columns-format) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
445 (insert delimit-columns-after delimit-columns-str-after)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
446 ((eq delimit-columns-format 'padding) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
447 (insert spaces delimit-columns-after delimit-columns-str-after)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
448 (t |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
449 (insert delimit-columns-after spaces delimit-columns-str-after)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
450 )) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
451 (goto-char (max (point) delimit-columns-limit)))) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
452 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
453 |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
454 (defun delimit-columns-format (spaces) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
455 (cond ((null delimit-columns-format) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
456 (insert delimit-columns-after |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
457 delimit-columns-str-separator |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
458 delimit-columns-before)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
459 ((eq delimit-columns-format 'separator) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
460 (insert delimit-columns-after |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
461 spaces |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
462 delimit-columns-str-separator |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
463 delimit-columns-before)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
464 ((eq delimit-columns-format 'padding) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
465 (insert spaces |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
466 delimit-columns-after |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
467 delimit-columns-str-separator |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
468 delimit-columns-before)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
469 (t |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
470 (insert delimit-columns-after |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
471 delimit-columns-str-separator |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
472 spaces |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
473 delimit-columns-before)) |
001414add3a5
Now there is a column formatting mechanism.
Gerd Moellmann <gerd@gnu.org>
parents:
26040
diff
changeset
|
474 )) |
25761 | 475 |
476 | |
477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
478 | |
479 | |
480 (provide 'delim-col) | |
481 | |
482 | |
52401 | 483 ;;; arch-tag: 1cc0c5c5-1b2a-43e4-9ba5-bf9441cfd1a9 |
25761 | 484 ;;; delim-col.el ends here |