comparison lisp/prim/indent.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents 376386a54a3c
children 131b0175ea99
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
1 ;;; indent.el --- indentation commands for XEmacs 1 ;;; indent.el --- indentation commands for XEmacs
2
3 ;; Copyright (C) 1985, 1992, 1993, 1995 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
2 ;; Keywords: lisp languages tools 6 ;; Keywords: lisp languages tools
3
4 ;; Copyright (C) 1985, 1992, 1993, 1995 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 7
8 ;; This file is part of XEmacs. 8 ;; This file is part of XEmacs.
9 9
10 ;; XEmacs is free software; you can redistribute it and/or modify it 10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by 11 ;; under the terms of the GNU General Public License as published by
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details. 18 ;; General Public License for more details.
19 19
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA.
23 24
24 ;;; Synched up with: FSF 19.30. 25 ;;; Synched up with: FSF 19.30.
25 26
26 ;;; Commentary: 27 ;;; Commentary:
27 28
43 44
44 (defun indent-for-tab-command (&optional prefix-arg) 45 (defun indent-for-tab-command (&optional prefix-arg)
45 "Indent line in proper way for current major mode." 46 "Indent line in proper way for current major mode."
46 (interactive "P") 47 (interactive "P")
47 (if (eq indent-line-function 'indent-to-left-margin) 48 (if (eq indent-line-function 'indent-to-left-margin)
48 (insert-tab) 49 (insert-tab prefix-arg)
49 (if prefix-arg 50 (if prefix-arg
50 (funcall indent-line-function prefix-arg) 51 (funcall indent-line-function prefix-arg)
51 (funcall indent-line-function)))) 52 (funcall indent-line-function))))
52 53
53 (defun insert-tab () 54 (defun insert-tab (&optional prefix-arg)
54 (if abbrev-mode 55 (let ((count (prefix-numeric-value prefix-arg)))
55 (expand-abbrev)) 56 (if abbrev-mode
56 (if indent-tabs-mode 57 (expand-abbrev))
57 (insert ?\t) 58 (if indent-tabs-mode
58 (indent-to (* tab-width (1+ (/ (current-column) tab-width)))))) 59 (insert-char ?\t count)
60 ;; XEmacs: (Need the `1+')
61 (indent-to (* tab-width (1+ (/ (current-column) tab-width)))))))
59 62
60 (defun indent-rigidly (start end arg) 63 (defun indent-rigidly (start end arg)
61 "Indent all lines starting in the region sideways by ARG columns. 64 "Indent all lines starting in the region sideways by ARG columns.
62 Called from a program, takes three arguments, START, END and ARG." 65 Called from a program, takes three arguments, START, END and ARG."
63 (interactive "r\np") 66 (interactive "r\np")
75 (or eol-flag 78 (or eol-flag
76 (indent-to (max 0 (+ indent arg)) 0)) 79 (indent-to (max 0 (+ indent arg)) 0))
77 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) 80 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
78 (forward-line 1)) 81 (forward-line 1))
79 (move-marker end nil) 82 (move-marker end nil)
80 (setq zmacs-region-stays nil))) 83 (setq zmacs-region-stays nil))) ; XEmacs
81 84
82 (defun indent-line-to (column) 85 (defun indent-line-to (column)
83 "Indent current line to COLUMN. 86 "Indent current line to COLUMN.
84 This function removes or adds spaces and tabs at beginning of line 87 This function removes or adds spaces and tabs at beginning of line
85 only if necessary. It leaves point at end of indentation." 88 only if necessary. It leaves point at end of indentation."
204 (goto-char from) 207 (goto-char from)
205 (skip-chars-backward " \t") 208 (skip-chars-backward " \t")
206 (if (bolp) (setq from (point))) 209 (if (bolp) (setq from (point)))
207 (goto-char to) 210 (goto-char to)
208 (setq to (point-marker))) 211 (setq to (point-marker)))
209 (alter-text-property from (marker-position to) 'left-margin 212 (alter-text-property from (marker-position to) 'left-margin ; XEmacs
210 (lambda (v) (max (- left-margin) (+ inc (or v 0))))) 213 (lambda (v) (max (- left-margin) (+ inc (or v 0)))))
211 (indent-rigidly from (marker-position to) inc) 214 (indent-rigidly from (marker-position to) inc) ; XEmacs
212 (if auto-fill-function 215 (if auto-fill-function
213 (save-excursion 216 (save-excursion
214 (fill-region from (marker-position to) nil t t))) 217 (fill-region from (marker-position to) nil t t))) ; XEmacs
215 (move-marker to nil)) 218 (move-marker to nil))
216 219
217 (defun decrease-left-margin (from to inc) 220 (defun decrease-left-margin (from to inc)
218 "Make the left margin of the region smaller. 221 "Make the left margin of the region smaller.
219 With no prefix argument, decrease the indentation by `standard-indent'. 222 With no prefix argument, decrease the indentation by `standard-indent'.
267 (not (string-equal fill-prefix ""))) 270 (not (string-equal fill-prefix "")))
268 (if (equal fill-prefix 271 (if (equal fill-prefix
269 (buffer-substring 272 (buffer-substring
270 (point) (min (point-max) (+ (length fill-prefix) (point))))) 273 (point) (min (point-max) (+ (length fill-prefix) (point)))))
271 (forward-char (length fill-prefix))) 274 (forward-char (length fill-prefix)))
272 (if (and adaptive-fill-mode 275 (if (and adaptive-fill-mode adaptive-fill-regexp
273 (looking-at adaptive-fill-regexp)) 276 (looking-at adaptive-fill-regexp))
274 (goto-char (match-end 0)))) 277 (goto-char (match-end 0))))
275 ;; Skip centering or flushright indentation 278 ;; Skip centering or flushright indentation
276 (if (memq (current-justification) '(center right)) 279 (if (memq (current-justification) '(center right))
277 (skip-chars-forward " \t"))) 280 (skip-chars-forward " \t")))
331 (indent-relative t)) 334 (indent-relative t))
332 335
333 (defun indent-relative (&optional unindented-ok) 336 (defun indent-relative (&optional unindented-ok)
334 "Space out to under next indent point in previous nonblank line. 337 "Space out to under next indent point in previous nonblank line.
335 An indent point is a non-whitespace character following whitespace. 338 An indent point is a non-whitespace character following whitespace.
336 If the previous nonblank line has no indent points beyond 339 If the previous nonblank line has no indent points beyond the
337 the column point starts at, `tab-to-tab-stop' is done instead." 340 column point starts at, `tab-to-tab-stop' is done instead."
338 (interactive "P") 341 (interactive "P")
339 (if abbrev-mode (expand-abbrev)) 342 (if abbrev-mode (expand-abbrev))
340 (let ((start-column (current-column)) 343 (let ((start-column (current-column))
341 indent) 344 indent)
342 (save-excursion 345 (save-excursion
405 (setq count (1+ count))) 408 (setq count (1+ count)))
406 (insert ?\n) 409 (insert ?\n)
407 (while (> count 0) 410 (while (> count 0)
408 (insert "0123456789") 411 (insert "0123456789")
409 (setq count (1- count)))) 412 (setq count (1- count))))
413 ;; XEmacs
410 (insert (substitute-command-keys "\nTo install changes, type \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes]")) 414 (insert (substitute-command-keys "\nTo install changes, type \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes]"))
411 (goto-char (point-min))) 415 (goto-char (point-min)))
412 416
413 (defun edit-tab-stops-note-changes () 417 (defun edit-tab-stops-note-changes ()
414 "Put edited tab stops into effect." 418 "Put edited tab stops into effect."
462 (while (and (> (current-column) tabend) 466 (while (and (> (current-column) tabend)
463 (eq (preceding-char) ?\ )) 467 (eq (preceding-char) ?\ ))
464 (forward-char -1)) 468 (forward-char -1))
465 (delete-region (point) before)))))))) 469 (delete-region (point) before))))))))
466 470
471 ;(define-key global-map "\t" 'indent-for-tab-command)
472 ;(define-key esc-map "\034" 'indent-region)
473 ;(define-key ctl-x-map "\t" 'indent-rigidly)
474 ;(define-key esc-map "i" 'tab-to-tab-stop)
475
467 ;;; indent.el ends here 476 ;;; indent.el ends here