annotate lisp/delim-col.el @ 26088:b7aa6ac26872

Add support for large files, 64-bit Solaris, system locale codings. * Makefile.in (emacs): Set the LC_ALL environment variable to "C" when dumping, so that the dumped Emacs doesn't have stray locale info. (dired.o): Depend on systime.h. (editfns.o): Depend on coding.h. * alloc.c, buffer.c, callproc.c, ccl.c, charset.c, coding.c, data.c, dispnew.c, editfns.c, emacs.c, filelock.c, floatfns.c, hftctl.c, keyboard.c, process.c, sysdep.c, unexelf.c, unexhp9k800.c, unexsunos4.c, vmsfns.c, vmsgmalloc.c, w32faces.c, w32menu.c, w32term.c, w32xfns.c, xfaces.c, xfns.c, xmenu.c, xterm.c: Include <config.h> before any system include files. * alloc.c, buffer.c, ccl.c, data.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, frame.c, insdel.c, keymap.c, lread.c, m/alpha.h, print.c, search.c, sysdep.c, xdisp.c, xfaces.c, xfns.c, xmenu.c, xterm.c: Do not include <stdlib.h>, as <config.h> does this now. * callproc.c (Fcall_process): Synchronize messages locale before invoking strerror. Decode resulting string with locale-coding-system. * coding.c (Vlocale_coding_system): New var. (syms_of_coding): Adjust to above change. (emacs_strerror): New function. * coding.h (emacs_strerror, Vlocale_coding_system): New decls. * config.in (HAVE_STDIO_EXT_H, HAVE_TM_GMTOFF, HAVE___FPENDING, HAVE_FTELLO, HAVE_GETLOADAVG, HAVE_MBLEN, HAVE_MBRLEN, HAVE_STRSIGNAL): New macros. (BITS_PER_LONG): Default to 64 if _LP64 is defined. <stdlib.h>: Include if HAVE_STDLIB_H is defined and NOT_C_CODE isn't. * dired.c: Include "systime.h". (Ffile_attributes): Do not cast s.st_size to int; this loses information if int is 32 bits but st_size and EMACS_INT are larger. Treat large device numbers like large inode numbers. * dispnew.c (PENDING_OUTPUT_COUNT): Use __fpending if available. * editfns.c: Include coding.h. (emacs_strftime): Remove decl. (emacs_strftimeu): New decl. (emacs_memftimeu): Renamed from emacs_memftime; new arg UT. Use emacs_strftimeu instead of emacs_strftime. (Fformat_time_string): Convert format string using Vlocale_coding_system, and convert result back. Synchronize time locale before invoking lower level function. Invoke emacs_memftimeu, passing ut, instead of emacs_memftime. * emacs.c: Include <locale.h> if HAVE_SETLOCALE is defined. (Vmessages_locale, Vprevious_messages_locale, Vtime_locale, Vprevious_time_locale): New variables. (main): Invoke setlocale early, so that initial error messages are localized properly. But skip locale-setting if LC_ALL is "C". Fix up locale when it's safe to do so. (fixup_locale): Moved here from xterm.c. (synchronize_locale, synchronize_time_locale, synchronize_messages_locale): New functions. (syms_of_emacs): Accommodate above changes. * fileio.c (report_file_error): Convert strerror output according to Vlocale_coding_system. (Finsert_file_contents): Check for arithmetic overflow in computations that depend on file size. Report IO errors with emacs_strerror, not strerror. * fns.c (Fgethash): Declare dflt parameter. * gmalloc.c: Do not define const to nothing if HAVE_CONFIG_H is defined; that's config.h's job. * lisp.h (EMACS_INT, BITS_PER_EMACS_INT, EMACS_UINT): If _LP64, default these values to long, BITS_PER_LONG, and unsigned long. (VALBITS, MARKBIT, XINT): Do not assume 32-bit EMACS_INT. (PNTR_COMPARISON_TYPE): Default to EMACS_UINT, not to unsigned int. (code_convert_string_norecord, fixup_locale, synchronize_messages_locale, synchronize_time_locale, emacs_open, emacs_close, emacs_read, emacs_write): New decls. All Emacs callers of open, close, read, write changed to use emacs_open, emacs_close, emacs_read, emacs_write. * lread.c (file_offset, file_tell): New macros. All uses of ftell changed to file_tell. (saved_doc_string_position, prev_saved_doc_string_position): Now of type file_offset. (init_lread): Do not fix locale here; fixup_locale now does this. * m/amdahl.h, s/usg5-4.h: (NSIG): Remove. (NSIG_MINIMUM): New macro. * m/cydra5.h, m/dpx2.h, m/mips.h, m/pfa50.h, m/sps7.h, m/stride.h, m/ustation.h, s/gnu-linux.h, s/hpux.h, s/iris3-5.h, s/iris3-6.h, s/umips.h, s/usg5-4.h: (SIGIO): Do not undef. (BROKEN_SIGIO): New macro. * m/ustation.h: (SIGTSTP): Do not undef. (BROKEN_SIGTSTP): New macro. * s/gnu-linux.h: (SIGPOLL, SIGURG): Do not undef. (BROKEN_SIGPOLL, BROKEN_SIGURG): New macros. * s/ptx4.h: (SIGINFO): Do not undef. (BROKEN_SIGINFO): New macros. * m/delta.h, s/ptx.h, s/template.h: Doc fix. * mktime.c, strftime.c: Update to glibc 2.1.2 version, with some Emacs-related changes merged. * print.c (float_to_string): Prepend "-" to representation of a NaN if the NaN is negative. * process.c (sys_siglist): Omit if HAVE_STRSIGNAL. (wait_reading_process_input): Use emacs_strerror, not strerror. * process.c (status_message, sigchld_handler): Synchronize locale, then use strsignal istead of sys_siglist. * w32proc.c (sys_wait): Likewise. * s/aix3-1.h, s/bsd4-1.h, s/dgux.h, s/gnu-linux.h, s/hiuxmpp.h, s/hpux.h, s/iris3-5.h, s/iris3-6.h, s/irix3-3.h, s/osf1.h, s/rtu.h, s/sunos4-1.h, s/unipl5-0.h, s/unipl5-2.h, s/usg5-0.h, s/usg5-2-2.h, s/usg5-2.h, s/usg5-3.h, s/xenix.h: (open, close, read, write, INTERRUPTIBLE_OPEN, INTERRUPTIBLE_CLOSE, INTERRUPTIBLE_IO): Remove. * s/sol2-5.h (_LARGEFILE_SOURCE, _FILE_OFFSET_BITS): New macros. * sysdep.c (sys_read, sys_write, read, write, sys_close, close, sys_open, open): Remove. (emacs_open, emacs_close, emacs_read, emacs_write): Always define; the old INTERRUPTIBLE_OPEN, INTERRUPTIBLE_CLOSE, and INTERRUPTIBLE_IO macros are no longer used. (emacs_open): Renamed from sys_open. Merge BSD4_1 version. (emacs_close): Renamed from sys_close. (emacs_read): Renamed from sys_read. (emacs_write): Renamed from sys_write. (sys_siglist): Do not declare if HAVE_STRSIGNAL. (dup2): Do not print error on failure; the real dup2 doesn't. (strsignal): New function, defined if !HAVE_STRSIGNAL. * syssignal.h (SIGINFO): Undef if defined and if BROKEN_SIGINFO is defined. (SIGIO, SIGPOLL, SIGTSTP, SIGURG): Likewise. (NSIG): If less than NSIG_MINIMUM, define to NSIG_MINIMUM. (strsignal): Declare if !HAVE_STRSIGNAL. * unexelf.c (ElfBitsW, ELFSIZE, ElfExpandBitsW): New macros. (ElfW): Define in terms of ElfExpandBitsW. * w32proc.c (sys_siglist): Remove decl. * xdisp.c (decode_mode_spec): 3rd arg is int, not char, to comply with ANSI C. (display_string): Declare face_string_pos arg. * xfns.c (Fx_show_tip): Declare timeout param. * xterm.c: No need to include locale.h. (x_alloc_lighter_color, x_setup_relief_color): Pass arg as double, not float, for compatibility with ANSI C. (fixup_locale): Move to emacs.c. (x_term_init): Do not setlocale or fixup locale; the main program does this now.
author Paul Eggert <eggert@twinsun.com>
date Tue, 19 Oct 1999 07:25:11 +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