summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2005-05-10 15:09:50 +0000
committermichelou <michelou@epfl.ch>2005-05-10 15:09:50 +0000
commit171b8ec35104af9dce81e22756d5e8bb0ac1f2f2 (patch)
treea85fa5bc699842f2b1dcff43c578a72466575344
parentedbac1669b73170ed50d9d1b5b8edcb7ca92a275 (diff)
downloadscala-171b8ec35104af9dce81e22756d5e8bb0ac1f2f2.tar.gz
scala-171b8ec35104af9dce81e22756d5e8bb0ac1f2f2.tar.bz2
scala-171b8ec35104af9dce81e22756d5e8bb0ac1f2f2.zip
- 'scala-regexp-opt-charset' no more uses the i...
- 'scala-regexp-opt-charset' no more uses the internal function 'regexp-opt-charset'.
-rw-r--r--support/emacs/scala-mode.el55
1 files changed, 51 insertions, 4 deletions
diff --git a/support/emacs/scala-mode.el b/support/emacs/scala-mode.el
index 74e412fde8..61fbf4d3ca 100644
--- a/support/emacs/scala-mode.el
+++ b/support/emacs/scala-mode.el
@@ -17,10 +17,57 @@
;; (note that XEmacs is not supported currently, the function below
;; only works around a single incompatibility).
-(defun scala-regexp-opt-charset (cset)
- (regexp-opt-charset (if (integerp ?a)
- cset
- (mapcar #'char-to-string cset))))
+;;(defun scala-regexp-opt-charset (cset)
+;; (regexp-opt-charset (if (integerp ?a)
+;; cset
+;; (mapcar #'char-to-string cset))))
+(defun scala-regexp-opt-charset (chars)
+ ;;
+ ;; Return a regexp to match a character in CHARS.
+ ;;
+ ;; The basic idea is to find character ranges. Also we take care in the
+ ;; position of character set meta characters in the character set regexp.
+ ;;
+ (let* ((charmap (make-char-table 'case-table))
+ (start -1) (end -2)
+ (charset "")
+ (bracket "") (dash "") (caret ""))
+ ;;
+ ;; Make a character map but extract character set meta characters.
+ (dolist (char chars)
+ (case char
+ (?\]
+ (setq bracket "]"))
+ (?^
+ (setq caret "^"))
+ (?-
+ (setq dash "-"))
+ (otherwise
+ (aset charmap char t))))
+ ;;
+ ;; Make a character set from the map using ranges where applicable.
+ (map-char-table
+ (lambda (c v)
+ (when v
+ (if (= (1- c) end) (setq end c)
+ (if (> end (+ start 2))
+ (setq charset (format "%s%c-%c" charset start end))
+ (while (>= end start)
+ (setq charset (format "%s%c" charset start))
+ (incf start)))
+ (setq start c end c))))
+ charmap)
+ (when (>= end start)
+ (if (> end (+ start 2))
+ (setq charset (format "%s%c-%c" charset start end))
+ (while (>= end start)
+ (setq charset (format "%s%c" charset start))
+ (incf start))))
+ ;;
+ ;; Make sure a caret is not first and a dash is first or last.
+ (if (and (string-equal charset "") (string-equal bracket ""))
+ (concat "[" dash caret "]")
+ (concat "[" bracket charset caret dash "]"))))
;; Customization