Mercurial > emacs
comparison lisp/progmodes/delphi.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs | 1 ;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs |
2 | 2 |
3 ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005 |
4 ;; Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Ray Blaak <blaak@infomatch.com> | 6 ;; Author: Ray Blaak <blaak@infomatch.com> |
7 ;; Maintainer: FSF (Blaak's email addr bounces, Aug 2005) | |
6 ;; Keywords: languages | 8 ;; Keywords: languages |
7 | 9 |
8 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
9 | 11 |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify it under | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify it under |
17 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 19 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
18 ;; details. | 20 ;; details. |
19 | 21 |
20 ;; You should have received a copy of the GNU General Public License along with | 22 ;; You should have received a copy of the GNU General Public License along with |
21 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software | 23 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software |
22 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 24 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 | 25 |
24 ;;; Commentary: | 26 ;;; Commentary: |
25 | 27 |
26 ;; To enter Delphi mode when you find a Delphi source file, one must override | 28 ;; To enter Delphi mode when you find a Delphi source file, one must override |
27 ;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk) | 29 ;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk) |
61 ;; constructed beginnings. | 63 ;; constructed beginnings. |
62 | 64 |
63 ;;; Code: | 65 ;;; Code: |
64 | 66 |
65 (provide 'delphi) | 67 (provide 'delphi) |
66 | |
67 (defconst delphi-version | |
68 (let ((revision "$Revision: 3.8 $")) | |
69 (string-match ": \\([^ ]+\\)" revision) | |
70 (match-string 1 revision)) | |
71 "Version of this delphi mode.") | |
72 | 68 |
73 (eval-and-compile | 69 (eval-and-compile |
74 ;; Allow execution on pre Emacs 20 versions. | 70 ;; Allow execution on pre Emacs 20 versions. |
75 (or (fboundp 'when) | 71 (or (fboundp 'when) |
76 (defmacro when (test &rest body) | 72 (defmacro when (test &rest body) |
92 (defmacro with-current-buffer (buf &rest forms) | 88 (defmacro with-current-buffer (buf &rest forms) |
93 `(save-excursion (set-buffer ,buf) ,@forms))) | 89 `(save-excursion (set-buffer ,buf) ,@forms))) |
94 ) | 90 ) |
95 | 91 |
96 (defgroup delphi nil | 92 (defgroup delphi nil |
97 "Major mode for editing Delphi source in Emacs" | 93 "Major mode for editing Delphi source in Emacs." |
98 :version "21.1" | 94 :version "21.1" |
99 :group 'languages) | 95 :group 'languages) |
100 | 96 |
101 (defconst delphi-debug nil | 97 (defconst delphi-debug nil |
102 "True if in debug mode.") | 98 "True if in debug mode.") |
156 :group 'delphi) | 152 :group 'delphi) |
157 | 153 |
158 (defcustom delphi-newline-always-indents t | 154 (defcustom delphi-newline-always-indents t |
159 "*Non-nil means NEWLINE in Delphi mode should always reindent the current | 155 "*Non-nil means NEWLINE in Delphi mode should always reindent the current |
160 line, insert a blank line and move to the default indent column of the blank | 156 line, insert a blank line and move to the default indent column of the blank |
161 line. If nil, then no indentation occurs, and NEWLINE does the usual | 157 line. If nil, then no indentation occurs, and NEWLINE does the usual |
162 behaviour. This is useful when one needs to do customized indentation that | 158 behavior. This is useful when one needs to do customized indentation that |
163 differs from the default." | 159 differs from the default." |
164 :type 'boolean | 160 :type 'boolean |
165 :group 'delphi) | 161 :group 'delphi) |
166 | 162 |
167 (defcustom delphi-comment-face 'font-lock-comment-face | 163 (defcustom delphi-comment-face 'font-lock-comment-face |
179 :type 'face | 175 :type 'face |
180 :group 'delphi) | 176 :group 'delphi) |
181 | 177 |
182 (defcustom delphi-other-face nil | 178 (defcustom delphi-other-face nil |
183 "*Face used to color everything else." | 179 "*Face used to color everything else." |
184 :type 'face | 180 :type '(choice (const :tag "None" nil) face) |
185 :group 'delphi) | 181 :group 'delphi) |
186 | 182 |
187 (defconst delphi-directives | 183 (defconst delphi-directives |
188 '(absolute abstract assembler automated cdecl default dispid dynamic | 184 '(absolute abstract assembler automated cdecl default dispid dynamic |
189 export external far forward index inline message name near nodefault | 185 export external far forward index inline message name near nodefault |
740 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) | 736 (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) |
741 (setq p (delphi-token-end token)) | 737 (setq p (delphi-token-end token)) |
742 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) | 738 (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) |
743 (delphi-progress-done))))) | 739 (delphi-progress-done))))) |
744 | 740 |
745 (defconst delphi-ignore-changes t | 741 (defvar delphi-ignore-changes t |
746 "Internal flag to control if the delphi-mode responds to buffer changes. | 742 "Internal flag to control if the delphi-mode responds to buffer changes. |
747 Defaults to t in case the delphi-after-change function is called on a | 743 Defaults to t in case the delphi-after-change function is called on a |
748 non-delphi buffer. Set to nil in a delphi buffer. To override, just do: | 744 non-delphi buffer. Set to nil in a delphi buffer. To override, just do: |
749 (let ((delphi-ignore-changes t)) ...)") | 745 (let ((delphi-ignore-changes t)) ...)") |
750 | 746 |
1514 (set-marker marked-point (point))) | 1510 (set-marker marked-point (point))) |
1515 ;; Advance our marked point after inserted spaces. | 1511 ;; Advance our marked point after inserted spaces. |
1516 (set-marker-insertion-type marked-point t) | 1512 (set-marker-insertion-type marked-point t) |
1517 (when (/= old-indent new-indent) | 1513 (when (/= old-indent new-indent) |
1518 (delete-region line-start (point)) | 1514 (delete-region line-start (point)) |
1519 (insert (make-string new-indent ?\ ))) | 1515 (insert (make-string new-indent ?\s))) |
1520 (goto-char marked-point) | 1516 (goto-char marked-point) |
1521 (set-marker marked-point nil)))) | 1517 (set-marker marked-point nil)))) |
1522 | 1518 |
1523 (defvar delphi-mode-abbrev-table nil | 1519 (defvar delphi-mode-abbrev-table nil |
1524 "Abbrev table in use in delphi-mode buffers.") | 1520 "Abbrev table in use in delphi-mode buffers.") |
1534 ;; Writes a message to the end of the specified buffer. | 1530 ;; Writes a message to the end of the specified buffer. |
1535 (with-current-buffer to-buffer | 1531 (with-current-buffer to-buffer |
1536 (save-selected-window | 1532 (save-selected-window |
1537 (switch-to-buffer-other-window to-buffer) | 1533 (switch-to-buffer-other-window to-buffer) |
1538 (goto-char (point-max)) | 1534 (goto-char (point-max)) |
1539 (set-window-dot (get-buffer-window to-buffer) (point)) | 1535 (set-window-point (get-buffer-window to-buffer) (point)) |
1540 (insert the-msg)))) | 1536 (insert the-msg)))) |
1541 | 1537 |
1542 ;; Debugging helpers: | 1538 ;; Debugging helpers: |
1543 | 1539 |
1544 (defvar delphi-debug-buffer nil | 1540 (defvar delphi-debug-buffer nil |
1779 (end-comment (delphi-comment-block-end comment)) | 1775 (end-comment (delphi-comment-block-end comment)) |
1780 (comment-start (delphi-token-start start-comment)) | 1776 (comment-start (delphi-token-start start-comment)) |
1781 (comment-end (delphi-token-end end-comment)) | 1777 (comment-end (delphi-token-end end-comment)) |
1782 (content-start (delphi-comment-content-start start-comment)) | 1778 (content-start (delphi-comment-content-start start-comment)) |
1783 (content-indent (delphi-column-of content-start)) | 1779 (content-indent (delphi-column-of content-start)) |
1784 (content-prefix (make-string content-indent ?\ )) | 1780 (content-prefix (make-string content-indent ?\s)) |
1785 (content-prefix-re delphi-leading-spaces-re) | 1781 (content-prefix-re delphi-leading-spaces-re) |
1786 (p nil) | 1782 (p nil) |
1787 (marked-point (point-marker))) ; Maintain our position reliably. | 1783 (marked-point (point-marker))) ; Maintain our position reliably. |
1788 (when (eq 'comment-single-line comment-kind) | 1784 (when (eq 'comment-single-line comment-kind) |
1789 ;; // style comments need more work. | 1785 ;; // style comments need more work. |
1790 (setq content-prefix | 1786 (setq content-prefix |
1791 (let ((comment-indent (delphi-column-of comment-start))) | 1787 (let ((comment-indent (delphi-column-of comment-start))) |
1792 (concat (make-string comment-indent ?\ ) "//" | 1788 (concat (make-string comment-indent ?\s) "//" |
1793 (make-string (- content-indent comment-indent 2) | 1789 (make-string (- content-indent comment-indent 2) |
1794 ?\ ))) | 1790 ?\s))) |
1795 content-prefix-re (concat delphi-leading-spaces-re | 1791 content-prefix-re (concat delphi-leading-spaces-re |
1796 "//" | 1792 "//" |
1797 delphi-spaces-re) | 1793 delphi-spaces-re) |
1798 comment-end (if (delphi-is-literal-end comment-end) | 1794 comment-end (if (delphi-is-literal-end comment-end) |
1799 ;; Don't include the trailing newline. | 1795 ;; Don't include the trailing newline. |
1861 (delphi-newline) | 1857 (delphi-newline) |
1862 (let* ((start-comment (delphi-comment-block-start comment)) | 1858 (let* ((start-comment (delphi-comment-block-start comment)) |
1863 (comment-start (delphi-token-start start-comment)) | 1859 (comment-start (delphi-token-start start-comment)) |
1864 (content-start (delphi-comment-content-start start-comment)) | 1860 (content-start (delphi-comment-content-start start-comment)) |
1865 (prefix | 1861 (prefix |
1866 (concat (make-string (delphi-column-of comment-start) ?\ ) "//" | 1862 (concat (make-string (delphi-column-of comment-start) ?\s) "//" |
1867 (make-string (- content-start comment-start 2) ?\ )))) | 1863 (make-string (- content-start comment-start 2) ?\s)))) |
1868 (delete-horizontal-space) | 1864 (delete-horizontal-space) |
1869 (newline) | 1865 (newline) |
1870 (insert prefix))))) | 1866 (insert prefix))))) |
1871 | 1867 |
1872 (defun delphi-match-token (token limit) | 1868 (defun delphi-match-token (token limit) |
2006 (let ((delphi-verbose t)) | 2002 (let ((delphi-verbose t)) |
2007 (delphi-progress-start) | 2003 (delphi-progress-start) |
2008 (delphi-parse-region (point-min) (point-max)) | 2004 (delphi-parse-region (point-min) (point-max)) |
2009 (delphi-progress-done)))) | 2005 (delphi-progress-done)))) |
2010 | 2006 |
2011 (run-hooks 'delphi-mode-hook)) | 2007 (run-mode-hooks 'delphi-mode-hook)) |
2012 | 2008 |
2009 ;;; arch-tag: 410e192d-e9b5-4397-ad62-12340fc3fa41 | |
2013 ;;; delphi.el ends here | 2010 ;;; delphi.el ends here |