aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Nicolaescu2007-06-21 22:55:44 +0000
committerDan Nicolaescu2007-06-21 22:55:44 +0000
commit247eedf8e9e01c4fe0fdc3a474f3763cacacc2c2 (patch)
tree1e79f39aeb146e42f6afd980ddebeffb622762af
parentd217d3901c15b284843513d783891bfb1eea3723 (diff)
downloademacs-247eedf8e9e01c4fe0fdc3a474f3763cacacc2c2.tar.gz
emacs-247eedf8e9e01c4fe0fdc3a474f3763cacacc2c2.zip
vera-mode.el (vera-mode): Fix `commend-end-skip' setting.
(vera-font-lock-match-item): Fix doc string. (vera-in-comment-p): Remove unused function. (vera-skip-forward-literal,vera-skip-backward-literal): Improve code, use `syntax-ppss'. (vera-forward-syntactic-ws): Fix argument order. (vera-prepare-search): Use `with-syntax-table'. (vera-indent-line): Fix doc string. (vera-electric-tab): Fix doc string. (vera-expand-abbrev): Define alias instead of using `fset'. (vera-comment-uncomment-region): Use `comment-start-skip'.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/progmodes/vera-mode.el106
2 files changed, 57 insertions, 63 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3668a5a8c09..b8277ef6be7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
12007-06-21 Reto Zimmermann <reto@gnu.org>
2
3 * vera-mode.el (vera-mode): Fix `commend-end-skip' setting.
4 (vera-font-lock-match-item): Fix doc string.
5 (vera-in-comment-p): Remove unused function.
6 (vera-skip-forward-literal,vera-skip-backward-literal): Improve code,
7 use `syntax-ppss'.
8 (vera-forward-syntactic-ws): Fix argument order.
9 (vera-prepare-search): Use `with-syntax-table'.
10 (vera-indent-line): Fix doc string.
11 (vera-electric-tab): Fix doc string.
12 (vera-expand-abbrev): Define alias instead of using `fset'.
13 (vera-comment-uncomment-region): Use `comment-start-skip'.
14
12007-06-20 Reto Zimmermann <reto@gnu.org> 152007-06-20 Reto Zimmermann <reto@gnu.org>
2 16
3 * progmodes/vera-mode.el: New file. 17 * progmodes/vera-mode.el: New file.
diff --git a/lisp/progmodes/vera-mode.el b/lisp/progmodes/vera-mode.el
index f26fd02ab17..124aaceb1f9 100644
--- a/lisp/progmodes/vera-mode.el
+++ b/lisp/progmodes/vera-mode.el
@@ -5,14 +5,14 @@
5 5
6;; Author: Reto Zimmermann <reto@gnu.org> 6;; Author: Reto Zimmermann <reto@gnu.org>
7;; Maintainer: Reto Zimmermann <reto@gnu.org> 7;; Maintainer: Reto Zimmermann <reto@gnu.org>
8;; Version: 2.26 8;; Version: 2.28
9;; Keywords: languages vera 9;; Keywords: languages vera
10;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html 10;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html
11 11
12(defconst vera-version "2.18" 12(defconst vera-version "2.18"
13 "Vera Mode version number.") 13 "Vera Mode version number.")
14 14
15(defconst vera-time-stamp "2007-06-11" 15(defconst vera-time-stamp "2007-06-21"
16 "Vera Mode time stamp for last update.") 16 "Vera Mode time stamp for last update.")
17 17
18;; This file is part of GNU Emacs. 18;; This file is part of GNU Emacs.
@@ -106,7 +106,7 @@ are treated as single words otherwise."
106 106
107(defcustom vera-intelligent-tab t 107(defcustom vera-intelligent-tab t
108 "*Non-nil means `TAB' does indentation, word completion and tab insertion. 108 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
109That is, if preceeding character is part of a word then complete word, 109That is, if preceding character is part of a word then complete word,
110else if not at beginning of line then insert tab, 110else if not at beginning of line then insert tab,
111else if last command was a `TAB' or `RET' then dedent one step, 111else if last command was a `TAB' or `RET' then dedent one step,
112else indent current line. 112else indent current line.
@@ -315,7 +315,7 @@ Key bindings:
315 (set (make-local-variable 'comment-end) "") 315 (set (make-local-variable 'comment-end) "")
316 (set (make-local-variable 'comment-column) 40) 316 (set (make-local-variable 'comment-column) 40)
317 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *") 317 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
318 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *//+") 318 (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *\n")
319 (set (make-local-variable 'comment-indent-function) 'c-comment-indent) 319 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
320 (set (make-local-variable 'paragraph-start) "^$") 320 (set (make-local-variable 'paragraph-start) "^$")
321 (set (make-local-variable 'paragraph-separate) paragraph-start) 321 (set (make-local-variable 'paragraph-separate) paragraph-start)
@@ -606,8 +606,8 @@ Key bindings:
606 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face)) 606 (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face))
607 607
608(defun vera-font-lock-match-item (limit) 608(defun vera-font-lock-match-item (limit)
609 "Match, and move over, any declaration item after point. Adapted from 609 "Match, and move over, any declaration item after point.
610`font-lock-match-c-style-declaration-item-and-skip-to-next'." 610Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
611 (condition-case nil 611 (condition-case nil
612 (save-restriction 612 (save-restriction
613 (narrow-to-region (point-min) limit) 613 (narrow-to-region (point-min) limit)
@@ -687,7 +687,6 @@ Key bindings:
687 (t (:italic t :bold t))) 687 (t (:italic t :bold t)))
688 "Font lock mode face used to highlight @ definitions." 688 "Font lock mode face used to highlight @ definitions."
689 :group 'font-lock-highlighting-faces) 689 :group 'font-lock-highlighting-faces)
690(put 'vera-font-lock-number-face 'face-alias 'vera-font-lock-number)
691 690
692(defface vera-font-lock-function 691(defface vera-font-lock-function
693 '((((class color) (background light)) (:foreground "DarkCyan")) 692 '((((class color) (background light)) (:foreground "DarkCyan"))
@@ -695,7 +694,6 @@ Key bindings:
695 (t (:italic t :bold t))) 694 (t (:italic t :bold t)))
696 "Font lock mode face used to highlight predefined functions and tasks." 695 "Font lock mode face used to highlight predefined functions and tasks."
697 :group 'font-lock-highlighting-faces) 696 :group 'font-lock-highlighting-faces)
698(put 'vera-font-lock-function-face 'face-alias 'vera-font-lock-function)
699 697
700(defface vera-font-lock-interface 698(defface vera-font-lock-interface
701 '((((class color) (background light)) (:foreground "Grey40")) 699 '((((class color) (background light)) (:foreground "Grey40"))
@@ -703,13 +701,8 @@ Key bindings:
703 (t (:italic t :bold t))) 701 (t (:italic t :bold t)))
704 "Font lock mode face used to highlight interface names." 702 "Font lock mode face used to highlight interface names."
705 :group 'font-lock-highlighting-faces) 703 :group 'font-lock-highlighting-faces)
706(put 'vera-font-lock-interface-face 'face-alias 'vera-font-lock-interface)
707
708(defun vera-fontify-buffer ()
709 "Fontify buffer."
710 (interactive)
711 (font-lock-fontify-buffer))
712 704
705(defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
713 706
714;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 707;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
715;;; Indentation 708;;; Indentation
@@ -789,7 +782,7 @@ the offset is simply returned."
789;; help functions 782;; help functions
790 783
791(defsubst vera-point (position) 784(defsubst vera-point (position)
792 "Returns the value of point at certain commonly referenced POSITIONs. 785 "Return the value of point at certain commonly referenced POSITIONs.
793POSITION can be one of the following symbols: 786POSITION can be one of the following symbols:
794 bol -- beginning of line 787 bol -- beginning of line
795 eol -- end of line 788 eol -- end of line
@@ -820,29 +813,34 @@ This function does not modify point or mark."
820 ((nth 4 state) 'comment) 813 ((nth 4 state) 'comment)
821 (t nil))))) 814 (t nil)))))
822 815
823(defun vera-in-comment-p ()
824 "Determine if point is in a Vera comment."
825 (save-excursion
826 (re-search-backward "\\(/\\*\\)\\|\\(\\*/\\)" nil t)
827 (match-string 1)))
828
829(defun vera-skip-forward-literal () 816(defun vera-skip-forward-literal ()
830 "Skip forward literal and return t if within one." 817 "Skip forward literal and return t if within one."
831 (let ((state (save-excursion (parse-partial-sexp (point-min) (point))))) 818 (let ((state (save-excursion
832 (cond 819 (if (fboundp 'syntax-ppss)
833 ((nth 3 state) (search-forward "\"") t) ; inside string 820 (syntax-ppss)
834 ((nth 7 state) (forward-line 1) t) ; inside // comment 821 (parse-partial-sexp (point-min) (point))))))
835 ((nth 4 state) (search-forward "*/") t) ; inside /* */ comment 822 (when (nth 8 state)
836 (t nil)))) 823 ;; Inside a string or comment.
824 (goto-char (nth 8 state))
825 (if (nth 3 state)
826 ;; A string.
827 (condition-case nil (forward-sexp 1)
828 ;; Can't find end of string: it extends til end of buffer.
829 (error (goto-char (point-max))))
830 ;; A comment.
831 (forward-comment 1))
832 t)))
837 833
838(defun vera-skip-backward-literal () 834(defun vera-skip-backward-literal ()
839 "Skip backward literal and return t if within one." 835 "Skip backward literal and return t if within one."
840 (let ((state (save-excursion (parse-partial-sexp (point-min) (point))))) 836 (let ((state (save-excursion
841 (cond 837 (if (fboundp 'syntax-ppss)
842 ((nth 3 state) (search-backward "\"") t) ; inside string 838 (syntax-ppss)
843 ((nth 7 state) (search-backward "//") t) ; inside // comment 839 (parse-partial-sexp (point-min) (point))))))
844 ((nth 4 state) (search-backward "/*") t) ; inside /* */ comment 840 (when (nth 8 state)
845 (t nil)))) 841 ;; Inside a string or comment.
842 (goto-char (nth 8 state))
843 t)))
846 844
847(defsubst vera-re-search-forward (regexp &optional bound noerror) 845(defsubst vera-re-search-forward (regexp &optional bound noerror)
848 "Like `re-search-forward', but skips over matches in literals." 846 "Like `re-search-forward', but skips over matches in literals."
@@ -868,7 +866,7 @@ This function does not modify point or mark."
868 (let* ((lim (or lim (point-max))) 866 (let* ((lim (or lim (point-max)))
869 (here lim) 867 (here lim)
870 (hugenum (point-max))) 868 (hugenum (point-max)))
871 (narrow-to-region lim (point)) 869 (narrow-to-region (point) lim)
872 (while (/= here (point)) 870 (while (/= here (point))
873 (setq here (point)) 871 (setq here (point))
874 (forward-comment hugenum) 872 (forward-comment hugenum)
@@ -892,25 +890,8 @@ This function does not modify point or mark."
892 (beginning-of-line))))))) 890 (beginning-of-line)))))))
893 891
894(defmacro vera-prepare-search (&rest body) 892(defmacro vera-prepare-search (&rest body)
895 "Switch to syntax table that includes '_', then execute BODY, and finally 893 "Execute BODY with a syntax table that includes '_'."
896restore the old environment. Used for consistent searching." 894 `(with-syntax-table vera-mode-ext-syntax-table ,@body))
897 `(let ((current-syntax-table (syntax-table))
898 result
899 (restore-prog ; program to restore enviroment
900 '(progn
901 ;; restore syntax table
902 (set-syntax-table current-syntax-table))))
903 ;; use extended syntax table
904 (set-syntax-table vera-mode-ext-syntax-table)
905 ;; execute BODY safely
906 (setq result
907 (condition-case info
908 (progn ,@body)
909 (error (eval restore-prog) ; restore environment on error
910 (error (cadr info))))) ; pass error up
911 ;; restore environment
912 (eval restore-prog)
913 result))
914 895
915;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 896;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
916;; comment indentation functions 897;; comment indentation functions
@@ -1198,7 +1179,7 @@ try to increase performance by using this macro."
1198 (goto-char placeholder) 1179 (goto-char placeholder)
1199 (vera-add-syntax 'statement (vera-point 'boi))) 1180 (vera-add-syntax 'statement (vera-point 'boi)))
1200 ;; CASE 9: at the beginning of a substatement? 1181 ;; CASE 9: at the beginning of a substatement?
1201 ;; is this line preceeded by a substatement opening statement? 1182 ;; is this line preceded by a substatement opening statement?
1202 ((save-excursion (vera-backward-syntactic-ws nil t) 1183 ((save-excursion (vera-backward-syntactic-ws nil t)
1203 (when (= (preceding-char) ?\)) (backward-sexp)) 1184 (when (= (preceding-char) ?\)) (backward-sexp))
1204 (backward-word 1) 1185 (backward-word 1)
@@ -1223,9 +1204,8 @@ try to increase performance by using this macro."
1223;; indentation functions 1204;; indentation functions
1224 1205
1225(defun vera-indent-line () 1206(defun vera-indent-line ()
1226 "Indent the current line as Vera code. Optional SYNTAX is the 1207 "Indent the current line as Vera code.
1227syntactic information for the current line. Returns the amount of 1208Return the amount of indentation change (in columns)."
1228indentation change (in columns)."
1229 (interactive) 1209 (interactive)
1230 (vera-prepare-search 1210 (vera-prepare-search
1231 (let* ((syntax (vera-guess-basic-syntax)) 1211 (let* ((syntax (vera-guess-basic-syntax))
@@ -1274,8 +1254,9 @@ Calls `indent-region' for whole buffer."
1274;; electrifications 1254;; electrifications
1275 1255
1276(defun vera-electric-tab (&optional prefix-arg) 1256(defun vera-electric-tab (&optional prefix-arg)
1277 "If preceeding character is part of a word or a paren then hippie-expand, 1257 "Do what I mean (indent, expand, tab, change indent, etc..).
1278else if right of non whitespace on line then tab-to-tab-stop, 1258If preceding character is part of a word or a paren then `hippie-expand',
1259else if right of non whitespace on line then `tab-to-tab-stop',
1279else if last command was a tab or return then dedent one step or if a comment 1260else if last command was a tab or return then dedent one step or if a comment
1280toggle between normal indent and inline comment indent, 1261toggle between normal indent and inline comment indent,
1281else indent `correctly'. 1262else indent `correctly'.
@@ -1424,9 +1405,8 @@ If `vera-intelligent-tab' is nil, always indent line."
1424 t)) 1405 t))
1425 1406
1426;; function for expanding abbrevs and dabbrevs 1407;; function for expanding abbrevs and dabbrevs
1427(defun vera-expand-abbrev (arg)) 1408(defalias 'vera-expand-abbrev
1428(fset 'vera-expand-abbrev (make-hippie-expand-function 1409 (make-hippie-expand-function '(try-expand-dabbrev
1429 '(try-expand-dabbrev
1430 try-expand-dabbrev-all-buffers 1410 try-expand-dabbrev-all-buffers
1431 vera-try-expand-abbrev))) 1411 vera-try-expand-abbrev)))
1432 1412
@@ -1437,7 +1417,7 @@ If `vera-intelligent-tab' is nil, always indent line."
1437 "Comment region if not commented, uncomment region if already commented." 1417 "Comment region if not commented, uncomment region if already commented."
1438 (interactive "r\nP") 1418 (interactive "r\nP")
1439 (goto-char beg) 1419 (goto-char beg)
1440 (if (looking-at (regexp-quote comment-start)) 1420 (if (looking-at comment-start-skip)
1441 (comment-region beg end '(4)) 1421 (comment-region beg end '(4))
1442 (comment-region beg end))) 1422 (comment-region beg end)))
1443 1423