X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/ae940284fa77a6928f5162b7de859e67bdc7506c..b3253cd4b4bcbe1ab4ad1fdc98b30c33af70332c:/lisp/progmodes/delphi.el diff --git a/lisp/progmodes/delphi.el b/lisp/progmodes/delphi.el index 4c721fc622..2558456bc0 100644 --- a/lisp/progmodes/delphi.el +++ b/lisp/progmodes/delphi.el @@ -1,7 +1,7 @@ ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs ;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, -;; 2008, 2009 Free Software Foundation, Inc. +;; 2008, 2009, 2010 Free Software Foundation, Inc. ;; Authors: Ray Blaak , ;; Simon South @@ -628,7 +628,9 @@ routine.") (defun delphi-token-at (p) ;; Returns the token from parsing text at point p. (when (and (<= (point-min) p) (<= p (point-max))) - (cond ((delphi-literal-token-at p)) + (cond ((delphi-char-token-at p ?\n 'newline)) + + ((delphi-literal-token-at p)) ((delphi-space-token-at p)) @@ -638,7 +640,6 @@ routine.") ((delphi-char-token-at p ?\) 'close-group)) ((delphi-char-token-at p ?\[ 'open-group)) ((delphi-char-token-at p ?\] 'close-group)) - ((delphi-char-token-at p ?\n 'newline)) ((delphi-char-token-at p ?\; 'semicolon)) ((delphi-char-token-at p ?. 'dot)) ((delphi-char-token-at p ?, 'comma)) @@ -888,7 +889,24 @@ non-delphi buffer. Set to nil in a delphi buffer. To override, just do: (setq token (delphi-block-start token))) ;; Regular block start found. - ((delphi-is token-kind delphi-block-statements) (throw 'done token)) + ((delphi-is token-kind delphi-block-statements) + (throw 'done + ;; As a special case, when a "case" block appears + ;; within a record declaration (to denote a variant + ;; part), the record declaration should be considered + ;; the enclosing block. + (if (eq 'case token-kind) + (let ((enclosing-token + (delphi-block-start token + 'stop-on-class))) + (if + (eq 'record + (delphi-token-kind enclosing-token)) + (if stop-on-class + enclosing-token + (delphi-previous-token enclosing-token)) + token)) + token))) ;; A class/record start also begins a block. ((delphi-composite-type-start token last-token) @@ -1058,6 +1076,7 @@ non-delphi buffer. Set to nil in a delphi buffer. To override, just do: (token-kind nil) (from-kind (delphi-token-kind from-token)) (last-colon nil) + (last-of nil) (last-token nil)) (catch 'done (while token @@ -1101,9 +1120,17 @@ non-delphi buffer. Set to nil in a delphi buffer. To override, just do: ;; Ignore whitespace. ((delphi-is token-kind delphi-whitespace)) - ;; Remember any ':' we encounter, since that affects how we indent to - ;; a case statement. - ((eq 'colon token-kind) (setq last-colon token)) + ;; Remember any "of" we encounter, since that affects how we + ;; indent to a case statement within a record declaration + ;; (i.e. a variant part). + ((eq 'of token-kind) + (setq last-of token)) + + ;; Remember any ':' we encounter (until we reach an "of"), + ;; since that affects how we indent to case statements in + ;; general. + ((eq 'colon token-kind) + (unless last-of (setq last-colon token))) ;; A case statement delimits a previous statement. We indent labels ;; specially. @@ -1370,7 +1397,7 @@ non-delphi buffer. Set to nil in a delphi buffer. To override, just do: ;; Indent in from the expression. (delphi-indent-of last-token delphi-indent-level)) - ;; No enclosing expression; use the previous statment's + ;; No enclosing expression; use the previous statement's ;; indent. ((delphi-previous-indent-of token))))) @@ -1652,14 +1679,23 @@ before the indent, the point is moved to the indent." (defun delphi-tab () - "Indent the current line or insert a TAB, depending on the value of -`delphi-tab-always-indents' and the current line position." + "Indent the region, when Transient Mark mode is enabled and the region is +active. Otherwise, indent the current line or insert a TAB, depending on the +value of `delphi-tab-always-indents' and the current line position." (interactive) - (if (or delphi-tab-always-indents ; We are always indenting - ;; Or we are before the first non-space character on the line. - (save-excursion (skip-chars-backward delphi-space-chars) (bolp))) - (delphi-indent-line) - (insert "\t"))) + (cond ((use-region-p) + ;; If Transient Mark mode is enabled and the region is active, indent + ;; the entire region. + (indent-region (region-beginning) (region-end))) + ((or delphi-tab-always-indents + (save-excursion (skip-chars-backward delphi-space-chars) (bolp))) + ;; Otherwise, if we are configured always to indent (regardless of the + ;; point's position in the line) or we are before the first non-space + ;; character on the line, indent the line. + (delphi-indent-line)) + (t + ;; Otherwise, insert a tab character. + (insert "\t")))) (defun delphi-is-directory (path) @@ -1935,7 +1971,8 @@ This is ok since we do our own keyword/comment/string face coloring.") ;;;###autoload (defun delphi-mode (&optional skip-initial-parsing) "Major mode for editing Delphi code. \\ -\\[delphi-tab]\t- Indents the current line for Delphi code. +\\[delphi-tab]\t- Indents the current line (or region, if Transient Mark mode +\t is enabled and the region is active) of Delphi code. \\[delphi-find-unit]\t- Search for a Delphi source file. \\[delphi-fill-comment]\t- Fill the current comment. \\[delphi-new-comment-line]\t- If in a // comment, do a new comment line.