annotate lisp/textmodes/text-mode.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 3f3121176533
children 1551195f02c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands.
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
2
7300
cc7cd83ccf3f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6323
diff changeset
3 ;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 775
diff changeset
4
775
1ca26ccad38e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 727
diff changeset
5 ;; Maintainer: FSF
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
22 ;; Boston, MA 02111-1307, USA.
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
23
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
24 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
25
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
26 ;; This package provides the fundamental text mode documented in the
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
27 ;; Emacs user's manual.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
28
775
1ca26ccad38e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 727
diff changeset
29 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30
19589
8c19d570a391 (text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18256
diff changeset
31 (defvar text-mode-hook nil
8c19d570a391 (text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18256
diff changeset
32 "Normal hook run when entering Text mode and many related modes.")
8c19d570a391 (text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18256
diff changeset
33
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
34 (defvar text-mode-variant nil
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
35 "Non-nil if this buffer's major mode is a variant of Text mode.")
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
36
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (defvar text-mode-syntax-table nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 "Syntax table used while in text mode.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 (defvar text-mode-abbrev-table nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 "Abbrev table used while in text mode.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 (define-abbrev-table 'text-mode-abbrev-table ())
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 (if text-mode-syntax-table
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 (setq text-mode-syntax-table (make-syntax-table))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 (modify-syntax-entry ?\" ". " text-mode-syntax-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 (modify-syntax-entry ?\\ ". " text-mode-syntax-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 (modify-syntax-entry ?' "w " text-mode-syntax-table))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 (defvar text-mode-map nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 "Keymap for Text mode.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 Many other modes, such as Mail mode, Outline mode and Indented Text mode,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 inherit all the commands defined in this map.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 (if text-mode-map
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 (setq text-mode-map (make-sparse-keymap))
4896
bc777b8e4b45 (text-mode-map): Bind ispell-complete-word to M-TAB.
Richard M. Stallman <rms@gnu.org>
parents: 4744
diff changeset
59 (define-key text-mode-map "\e\t" 'ispell-complete-word)
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
60 (define-key text-mode-map "\t" 'indent-relative)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 (define-key text-mode-map "\es" 'center-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (define-key text-mode-map "\eS" 'center-paragraph))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (defun text-mode ()
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
66 "Major mode for editing text written for humans to read.
18256
27f2dfb2c1de (text-mode): Let all-white lines separate paragraphs.
Richard M. Stallman <rms@gnu.org>
parents: 18222
diff changeset
67 In this mode, paragraphs are delimited only by blank or white lines.
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
68 You can thus get the full benefit of adaptive filling
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
69 (see the variable `adaptive-fill-mode').
6323
30bb1685217f (text-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6258
diff changeset
70 \\{text-mode-map}
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
71 Turning on Text mode runs the normal hook `text-mode-hook'."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (kill-all-local-variables)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (use-local-map text-mode-map)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
75 (setq local-abbrev-table text-mode-abbrev-table)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
76 (set-syntax-table text-mode-syntax-table)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
77 (make-local-variable 'paragraph-start)
18256
27f2dfb2c1de (text-mode): Let all-white lines separate paragraphs.
Richard M. Stallman <rms@gnu.org>
parents: 18222
diff changeset
78 (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter))
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
79 (make-local-variable 'paragraph-separate)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
80 (setq paragraph-separate paragraph-start)
22631
3f3121176533 (text-mode): Locally set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents: 19620
diff changeset
81 (make-local-variable 'indent-line-function)
3f3121176533 (text-mode): Locally set indent-line-function.
Richard M. Stallman <rms@gnu.org>
parents: 19620
diff changeset
82 (setq indent-line-function 'indent-relative-maybe)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 (setq mode-name "Text")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (setq major-mode 'text-mode)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
85 (run-hooks 'text-mode-hook))
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
86
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
87 (defun paragraph-indent-text-mode ()
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
88 "Major mode for editing text, with leading spaces starting a paragraph.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
89 In this mode, you do not need blank lines between paragraphs
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
90 when the first line of the following paragraph starts with whitespace.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
91 Special commands:
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
92 \\{text-mode-map}
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
93 Turning on Paragraph-Indent Text mode runs the normal hooks
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
94 `text-mode-hook' and `paragraph-indent-text-mode-hook'."
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
95 (interactive)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
96 (kill-all-local-variables)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
97 (use-local-map text-mode-map)
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
98 (setq mode-name "Parindent")
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
99 (setq major-mode 'paragraph-indent-text-mode)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (setq local-abbrev-table text-mode-abbrev-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (set-syntax-table text-mode-syntax-table)
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
102 (run-hooks 'text-mode-hook 'paragraph-indent-text-mode-hook))
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
103
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
104 (defalias 'indented-text-mode 'text-mode)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105
19620
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
106 (defun text-mode-hook-identify ()
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
107 "Mark that this mode has run `text-mode-hook'.
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
108 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on."
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
109 (make-local-variable 'text-mode-variant)
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
110 (setq text-mode-variant t))
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
111
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
112 (add-hook 'text-mode-hook 'text-mode-hook-identify)
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
113
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
114 (defun toggle-text-mode-auto-fill ()
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
115 "Toggle whether to use Auto Fill in Text mode and related modes.
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
116 This command affects all buffers that use modes related to Text mode,
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
117 both existing buffers and buffers that you subsequently create."
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
118 (interactive)
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
119 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook)))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
120 (buffers (buffer-list)))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
121 (if enable-mode
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
122 (add-hook 'text-mode-hook 'turn-on-auto-fill)
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
123 (remove-hook 'text-mode-hook 'turn-on-auto-fill))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
124 (while buffers
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
125 (with-current-buffer (car buffers)
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
126 (if text-mode-variant
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
127 (auto-fill-mode (if enable-mode 1 0))))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
128 (setq buffers (cdr buffers)))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
129 (message "Auto Fill %s in Text modes"
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
130 (if enable-mode "enabled" "disabled"))))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
131
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 (defun center-paragraph ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 "Center each nonblank line in the paragraph at or after point.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
134 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (forward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (or (bolp) (newline 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (let ((end (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (backward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (center-region (point) end))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 (defun center-region (from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 "Center each nonblank line starting in the region.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
145 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146 (interactive "r")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 (if (> from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 (let ((tem to))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 (setq to from from tem)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151 (save-restriction
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
152 (narrow-to-region from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 (goto-char from)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 (while (not (eobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 (or (save-excursion (skip-chars-forward " \t") (eolp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 (center-line))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 (forward-line 1)))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
158
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
159 (defun center-line (&optional nlines)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 "Center the line point is on, within the width specified by `fill-column'.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 This means adjusting the indentation so that it equals
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
162 the distance between the end of the text and `fill-column'.
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
163 The argument NLINES says how many lines to center."
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
164 (interactive "P")
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
165 (if nlines (setq nlines (prefix-numeric-value nlines)))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
166 (while (not (eq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
167 (save-excursion
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
168 (let ((lm (current-left-margin))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
169 line-length)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
170 (beginning-of-line)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
171 (delete-horizontal-space)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
172 (end-of-line)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
173 (delete-horizontal-space)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
174 (setq line-length (current-column))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
175 (if (> (- fill-column lm line-length) 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
176 (indent-line-to
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
177 (+ lm (/ (- fill-column lm line-length) 2))))))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
178 (cond ((null nlines)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
179 (setq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
180 ((> nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
181 (setq nlines (1- nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
182 (forward-line 1))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
183 ((< nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
184 (setq nlines (1+ nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
185 (forward-line -1)))))
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
186
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
187 ;;; text-mode.el ends here