aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2007-08-18 08:33:06 +0000
committerMartin Rudalics2007-08-18 08:33:06 +0000
commitbef83666556ed398df332e7ded92529b783e43f2 (patch)
tree63eda4865404f973282f4eeb084ef1dc368df057
parentc2659333c28521b1ca9263d5a9dae88d853e7292 (diff)
downloademacs-bef83666556ed398df332e7ded92529b783e43f2.tar.gz
emacs-bef83666556ed398df332e7ded92529b783e43f2.zip
(ada-create-syntax-table): Move
set-syntax-table from here to ... (ada-mode): ... here. Do not change global value of comment-multi-line. Call new function ada-initialize-syntax-table-properties and add new function ada-handle-syntax-table-properties to font-lock-mode-hook. (ada-deactivate-properties, ada-initialize-properties): Replace by new functions ... (ada-handle-syntax-table-properties) (ada-initialize-syntax-table-properties) (ada-set-syntax-table-properties): ... to set up syntax-table properties uniformly, independently from whether font-lock-mode is enabled or not. Handle read-only buffers and do not change undo-list when setting syntax-table properties. (ada-after-change-function): Use ada-set-syntax-table-properties.
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/progmodes/ada-mode.el113
2 files changed, 79 insertions, 53 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 69d753121ea..027f4193254 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,22 @@
12007-08-18 Martin Rudalics <rudalics@gmx.at>
2
3 * progmodes/ada-mode.el (ada-create-syntax-table): Move
4 set-syntax-table from here to ...
5 (ada-mode): ... here. Do not change global value of
6 comment-multi-line. Call new function
7 ada-initialize-syntax-table-properties and add new function
8 ada-handle-syntax-table-properties to font-lock-mode-hook.
9 (ada-deactivate-properties, ada-initialize-properties): Replace
10 by new functions ...
11 (ada-handle-syntax-table-properties)
12 (ada-initialize-syntax-table-properties)
13 (ada-set-syntax-table-properties): ... to set up syntax-table
14 properties uniformly, independently from whether font-lock-mode
15 is enabled or not. Handle read-only buffers and do not change
16 undo-list when setting syntax-table properties.
17 (ada-after-change-function): Use
18 ada-set-syntax-table-properties.
19
12007-08-17 Bob Rogers <rogers-emacs@rgrjr.dyndns.org> (tiny change) 202007-08-17 Bob Rogers <rogers-emacs@rgrjr.dyndns.org> (tiny change)
2 21
3 * progmode/cperl-mode.el (cperl-look-at-leading-count) 22 * progmode/cperl-mode.el (cperl-look-at-leading-count)
diff --git a/lisp/progmodes/ada-mode.el b/lisp/progmodes/ada-mode.el
index c9a69005eaf..aa3aea0d71b 100644
--- a/lisp/progmodes/ada-mode.el
+++ b/lisp/progmodes/ada-mode.el
@@ -829,13 +829,12 @@ the 4 file locations can be clicked on and jumped to."
829;; Thus their syntax property is changed automatically, and we can still use 829;; Thus their syntax property is changed automatically, and we can still use
830;; the standard Emacs functions for sexp (see `ada-in-string-p') 830;; the standard Emacs functions for sexp (see `ada-in-string-p')
831;; 831;;
832;; On Emacs, this is done through the `syntax-table' text property. The 832;; On Emacs, this is done through the `syntax-table' text property. The
833;; modification is done automatically each time the user as typed a new 833;; corresponding action is applied automatically each time the buffer
834;; character. This is already done in `font-lock-mode' (in 834;; changes. If `font-lock-mode' is enabled (the default) the action is
835;; `font-lock-syntactic-keywords', so we take advantage of the existing 835;; set up by `font-lock-syntactic-keywords'. Otherwise, we do it
836;; mechanism. If font-lock-mode is not activated, we do it by hand in 836;; manually in `ada-after-change-function'. The proper method is
837;; `ada-after-change-function', thanks to `ada-deactivate-properties' and 837;; installed by `ada-handle-syntax-table-properties'.
838;; `ada-initialize-properties'.
839;; 838;;
840;; on XEmacs, the `syntax-table' property does not exist and we have to use a 839;; on XEmacs, the `syntax-table' property does not exist and we have to use a
841;; slow advice to `parse-partial-sexp' to do the same thing. 840;; slow advice to `parse-partial-sexp' to do the same thing.
@@ -852,7 +851,6 @@ The standard table declares `_' as a symbol constituent, the second one
852declares it as a word constituent." 851declares it as a word constituent."
853 (interactive) 852 (interactive)
854 (setq ada-mode-syntax-table (make-syntax-table)) 853 (setq ada-mode-syntax-table (make-syntax-table))
855 (set-syntax-table ada-mode-syntax-table)
856 854
857 ;; define string brackets (`%' is alternative string bracket, but 855 ;; define string brackets (`%' is alternative string bracket, but
858 ;; almost never used as such and throws font-lock and indentation 856 ;; almost never used as such and throws font-lock and indentation
@@ -936,50 +934,59 @@ declares it as a word constituent."
936 (insert (caddar change)) 934 (insert (caddar change))
937 (setq change (cdr change))))))) 935 (setq change (cdr change)))))))
938 936
939(defun ada-deactivate-properties () 937(defun ada-set-syntax-table-properties ()
940 "Deactivate Ada mode's properties handling. 938 "Assign `syntax-table' properties in accessible part of buffer.
941This would be a duplicate of font-lock if both are used at the same time." 939In particular, character constants are said to be strings, #...#
942 (remove-hook 'after-change-functions 'ada-after-change-function t)) 940are treated as numbers instead of gnatprep comments."
943 941 (let ((modified (buffer-modified-p))
944(defun ada-initialize-properties () 942 (buffer-undo-list t)
945 "Initialize some special text properties in the whole buffer. 943 (inhibit-read-only t)
946In particular, character constants are said to be strings, #...# are treated 944 (inhibit-point-motion-hooks t)
947as numbers instead of gnatprep comments." 945 (inhibit-modification-hooks t))
948 (save-excursion 946 (remove-text-properties (point-min) (point-max) '(syntax-table nil))
949 (save-restriction 947 (goto-char (point-min))
950 (widen) 948 (while (re-search-forward
951 (goto-char (point-min)) 949 ;; The following regexp was adapted from
952 (while (re-search-forward "'.'" nil t) 950 ;; `ada-font-lock-syntactic-keywords'.
953 (add-text-properties (match-beginning 0) (match-end 0) 951 "^[ \t]*\\(#\\(?:if\\|else\\|elsif\\|end\\)\\)\\|[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)"
954 '(syntax-table ("'" . ?\")))) 952 nil t)
955 (goto-char (point-min)) 953 (if (match-beginning 1)
956 (while (re-search-forward "^[ \t]*#" nil t) 954 (put-text-property
957 (add-text-properties (match-beginning 0) (match-end 0) 955 (match-beginning 1) (match-end 1) 'syntax-table '(11 . ?\n))
958 '(syntax-table (11 . 10)))) 956 (put-text-property
959 (set-buffer-modified-p nil) 957 (match-beginning 2) (match-end 2) 'syntax-table '(7 . ?'))
960 958 (put-text-property
961 ;; Setting this only if font-lock is not set won't work 959 (match-beginning 3) (match-end 3) 'syntax-table '(7 . ?'))))
962 ;; if the user activates or deactivates font-lock-mode, 960 (unless modified
963 ;; but will make things faster most of the time 961 (restore-buffer-modified-p nil))))
964 (add-hook 'after-change-functions 'ada-after-change-function nil t)
965 )))
966 962
967(defun ada-after-change-function (beg end old-len) 963(defun ada-after-change-function (beg end old-len)
968 "Called when the region between BEG and END was changed in the buffer. 964 "Called when the region between BEG and END was changed in the buffer.
969OLD-LEN indicates what the length of the replaced text was." 965OLD-LEN indicates what the length of the replaced text was."
970 (let ((inhibit-point-motion-hooks t) 966 (save-excursion
971 (eol (point))) 967 (save-restriction
968 (let ((from (progn (goto-char beg) (line-beginning-position)))
969 (to (progn (goto-char end) (line-end-position))))
970 (narrow-to-region from to)
971 (save-match-data
972 (ada-set-syntax-table-properties))))))
973
974(defun ada-initialize-syntax-table-properties ()
975 "Assign `syntax-table' properties in current buffer."
972 (save-excursion 976 (save-excursion
973 (save-match-data 977 (save-restriction
974 (beginning-of-line) 978 (widen)
975 (remove-text-properties (point) eol '(syntax-table nil)) 979 (save-match-data
976 (while (re-search-forward "'.'" eol t) 980 (ada-set-syntax-table-properties))))
977 (add-text-properties (match-beginning 0) (match-end 0) 981 (add-hook 'after-change-functions 'ada-after-change-function nil t))
978 '(syntax-table ("'" . ?\")))) 982
979 (beginning-of-line) 983(defun ada-handle-syntax-table-properties ()
980 (if (looking-at "^[ \t]*#") 984 "Handle `syntax-table' properties."
981 (add-text-properties (match-beginning 0) (match-end 0) 985 (if font-lock-mode
982 '(syntax-table (11 . 10)))))))) 986 ;; `font-lock-mode' will take care of `syntax-table' properties.
987 (remove-hook 'after-change-functions 'ada-after-change-function t)
988 ;; Take care of `syntax-table' properties manually.
989 (ada-initialize-syntax-table-properties)))
983 990
984;;------------------------------------------------------------------ 991;;------------------------------------------------------------------
985;; Testing the grammatical context 992;; Testing the grammatical context
@@ -1150,6 +1157,8 @@ If you use ada-xref.el:
1150 1157
1151 (interactive) 1158 (interactive)
1152 (kill-all-local-variables) 1159 (kill-all-local-variables)
1160
1161 (set-syntax-table ada-mode-syntax-table)
1153 1162
1154 (set (make-local-variable 'require-final-newline) mode-require-final-newline) 1163 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
1155 1164
@@ -1340,7 +1349,7 @@ If you use ada-xref.el:
1340 (setq which-func-functions '(ada-which-function)) 1349 (setq which-func-functions '(ada-which-function))
1341 1350
1342 ;; Support for indent-new-comment-line (Especially for XEmacs) 1351 ;; Support for indent-new-comment-line (Especially for XEmacs)
1343 (setq comment-multi-line nil) 1352 (set (make-local-variable 'comment-multi-line) nil)
1344 1353
1345 (setq major-mode 'ada-mode 1354 (setq major-mode 'ada-mode
1346 mode-name "Ada") 1355 mode-name "Ada")
@@ -1377,9 +1386,8 @@ If you use ada-xref.el:
1377 ;; font-lock-mode 1386 ;; font-lock-mode
1378 1387
1379 (unless (featurep 'xemacs) 1388 (unless (featurep 'xemacs)
1380 (progn 1389 (ada-initialize-syntax-table-properties)
1381 (ada-initialize-properties) 1390 (add-hook 'font-lock-mode-hook 'ada-handle-syntax-table-properties nil t))
1382 (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t)))
1383 1391
1384 ;; the following has to be done after running the ada-mode-hook 1392 ;; the following has to be done after running the ada-mode-hook
1385 ;; because users might want to set the values of these variable 1393 ;; because users might want to set the values of these variable
@@ -5200,8 +5208,7 @@ Return nil if no body was found."
5200 ;; This sets the properties of the characters, so that ada-in-string-p 5208 ;; This sets the properties of the characters, so that ada-in-string-p
5201 ;; correctly handles '"' too... 5209 ;; correctly handles '"' too...
5202 '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?'))) 5210 '(("[^a-zA-Z0-9)]\\('\\)[^'\n]\\('\\)" (1 (7 . ?')) (2 (7 . ?')))
5203 ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n))) 5211 ("^[ \t]*\\(#\\(if\\|else\\|elsif\\|end\\)\\)" (1 (11 . ?\n)))))
5204 ))
5205 5212
5206(defvar ada-font-lock-keywords 5213(defvar ada-font-lock-keywords
5207 (eval-when-compile 5214 (eval-when-compile