From 3719a658add9455820e613016ea32ccf0f629530 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sat, 26 Jan 2008 10:01:03 +1030 Subject: [PATCH] * wesnoth-mode.el: Improved emacs21 support. No longer create spurious newlines when inserting tags around a region. (wesnoth-preprocessor-best-face): New function. --- wesnoth-mode.el | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 5575115..3801076 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -32,6 +32,7 @@ ;;; Changes: ;; 1.2.2+git +;; * Now compatible with GNU Emacs21. ;; * Added support for several new tags. ;; * Added menu entry for wesnoth-mode. ;; * Significant speed increase to indentation. @@ -40,6 +41,8 @@ ;; has been removed. ;; * Trailing whitespace is no longer created when creating a second consecutive ;; newline. +;; * Spurious newlines are no longer created when inserting a tag elements +;; around a region. ;; 1.2.2 ;; * Added functions: `wesnoth-indent', `wesnoth-element-closing', ;; `wesnoth-element', `wesnoth-element-opening', @@ -178,13 +181,19 @@ indent the line." '("\\(#[\t ]*.*$\\)" 1 "<")) "Highlighting syntactic keywords within wesnoth-mode.") +(defun wesnoth-preprocessor-best-face () + "Use `font-lock-preprocessor-face' when available." + (if (boundp 'font-lock-preprocessor-face) + (copy-face 'font-lock-preprocessor-face 'wesnoth-preprocessor-face) + (copy-face 'font-lock-keyword-face 'wesnoth-preprocessor-face))) + (defvar wesnoth-font-lock-keywords (list '("\\(#\\(?:define\\|\\(?:ifn?\\|un\\)def\\)\\)" - 1 font-lock-preprocessor-face) + 1 wesnoth-preprocessor-face) '("\\(#\\(?:define\\|\\(?:ifn?\\|un\\)def\\)\\)[\t ]+\\(\\w+\\)" 2 font-lock-function-name-face) - '("\\(#e\\(?:lse\\|nd\\(?:\\(?:de\\|i\\)f\\)\\)\\)" . font-lock-preprocessor-face) + '("\\(#e\\(?:lse\\|nd\\(?:\\(?:de\\|i\\)f\\)\\)\\)" . wesnoth-preprocessor-face) '("\\({[@~]?\\(\\w\\|\\.\\|/\\|-\\)+}\\)" (1 font-lock-function-name-face)) '("\\({\\(\\w\\|:\\)+\\|{[~@]?\\)" @@ -292,14 +301,13 @@ insert opening and closing tags around the specified region." (insert "[" tagname "]") (goto-char end) (beginning-of-line) - (or (looking-at "^[\t ]*$") - (progn - (end-of-line) - (newline))) - (end-of-line) - (insert "[/" tagname "]\n") + (if (looking-at "^[\t ]*$") + (open-line 1) + (end-of-line) + (newline)) + (insert "[/" tagname "]") (setq end (point)) ;; New target for indent-region - (indent-region start end)) + (indent-region start end nil)) (beginning-of-line) (or (looking-at "^[\t ]*$") (progn @@ -673,6 +681,7 @@ positions of the buffer, respectively." ;;; wesnoth-mode (define-derived-mode wesnoth-mode fundamental-mode "wesnoth-mode" "Major mode for editing WML." + (wesnoth-preprocessor-best-face) (set-syntax-table wesnoth-syntax-table) (set (make-local-variable 'outline-regexp) "[\t ]*#define") (set (make-local-variable 'comment-start) "#") -- 2.11.4.GIT