summaryrefslogtreecommitdiff
path: root/emacs/caml.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/caml.el')
-rw-r--r--emacs/caml.el91
1 files changed, 56 insertions, 35 deletions
diff --git a/emacs/caml.el b/emacs/caml.el
index 14dc74af60..939bd85f5d 100644
--- a/emacs/caml.el
+++ b/emacs/caml.el
@@ -10,8 +10,6 @@
;(* *)
;(***********************************************************************)
-;(* $Id: caml.el 12858 2012-08-10 14:45:51Z maranget $ *)
-
;;; caml.el --- OCaml code editing commands for Emacs
;; Luc Maranget, January 2008. A few jocaml additions.
(defconst caml-is-jocaml t)
@@ -409,26 +407,27 @@ have caml-electric-indent on, which see.")
"Syntax table in use in Caml mode buffers.")
(if caml-mode-syntax-table
()
- (setq caml-mode-syntax-table (make-syntax-table))
- ; backslash is an escape sequence
- (modify-syntax-entry ?\\ "\\" caml-mode-syntax-table)
- ; ( is first character of comment start
- (modify-syntax-entry ?\( "()1n" caml-mode-syntax-table)
- ; * is second character of comment start,
- ; and first character of comment end
- (modify-syntax-entry ?* ". 23n" caml-mode-syntax-table)
- ; ) is last character of comment end
- (modify-syntax-entry ?\) ")(4" caml-mode-syntax-table)
- ; backquote was a string-like delimiter (for character literals)
- ; (modify-syntax-entry ?` "\"" caml-mode-syntax-table)
- ; quote and underscore are part of words
- (modify-syntax-entry ?' "w" caml-mode-syntax-table)
- (modify-syntax-entry ?_ "w" caml-mode-syntax-table)
- ; ISO-latin accented letters and EUC kanjis are part of words
- (let ((i 160))
- (while (< i 256)
- (modify-syntax-entry i "w" caml-mode-syntax-table)
- (setq i (1+ i)))))
+ (let ((n (if (string-match "XEmacs" (emacs-version)) "" "n")))
+ (setq caml-mode-syntax-table (make-syntax-table))
+ ; backslash is an escape sequence
+ (modify-syntax-entry ?\\ "\\" caml-mode-syntax-table)
+ ; ( is first character of comment start
+ (modify-syntax-entry ?\( (concat "()1" n) caml-mode-syntax-table)
+ ; * is second character of comment start,
+ ; and first character of comment end
+ (modify-syntax-entry ?* (concat ". 23" n) caml-mode-syntax-table)
+ ; ) is last character of comment end
+ (modify-syntax-entry ?\) ")(4" caml-mode-syntax-table)
+ ; backquote was a string-like delimiter (for character literals)
+ ; (modify-syntax-entry ?` "\"" caml-mode-syntax-table)
+ ; quote and underscore are part of words
+ (modify-syntax-entry ?' "w" caml-mode-syntax-table)
+ (modify-syntax-entry ?_ "w" caml-mode-syntax-table)
+ ; ISO-latin accented letters and EUC kanjis are part of words
+ (let ((i 160))
+ (while (< i 256)
+ (modify-syntax-entry i "w" caml-mode-syntax-table)
+ (setq i (1+ i))))))
(defvar caml-mode-abbrev-table nil
"Abbrev table used for Caml mode buffers.")
@@ -695,14 +694,14 @@ the current point."
((looking-at "[ \t]*method")
(setq method-alist (cons index method-alist)))))
;; build menu
- (mapcar
- '(lambda (pair)
- (if (symbol-value (cdr pair))
- (setq menu-alist
- (cons
- (cons (car pair)
- (sort (symbol-value (cdr pair)) 'imenu--sort-by-name))
- menu-alist))))
+ (mapc
+ (lambda (pair)
+ (if (symbol-value (cdr pair))
+ (setq menu-alist
+ (cons
+ (cons (car pair)
+ (sort (symbol-value (cdr pair)) 'imenu--sort-by-name))
+ menu-alist))))
'(("Values" . value-alist)
("Types" . type-alist)
("Modules" . module-alist)
@@ -791,17 +790,32 @@ variable caml-mode-indentation."
;; In Emacs 19, the regexps in compilation-error-regexp-alist do not
;; match the error messages when the language is not English.
;; Hence we add a regexp.
+;; FIXME do we (still) have i18n of error messages ???
(defconst caml-error-regexp
"^[ A-\377]+ \"\\([^\"\n]+\\)\", [A-\377]+ \\([0-9]+\\)[-,:]"
"Regular expression matching the error messages produced by camlc.")
+;; Newer emacs versions support line/char ranges
+;; We will adapt OCaml to output error messages in a compatible format.
+;; In the meantime we add the new format here in addition to the old one.
+(defconst caml-error-regexp-newstyle
+ (concat "^[ A-\377]+ \"\\([^\"\n]+\\)\", line \\([0-9]+\\),"
+ "char \\([0-9]+\\) to line \\([0-9]+\\), char \\([0-9]+\\):")
+ "Regular expression matching the error messages produced by ocamlc/ocamlopt.")
+
(if (boundp 'compilation-error-regexp-alist)
- (or (assoc caml-error-regexp
- compilation-error-regexp-alist)
- (setq compilation-error-regexp-alist
- (cons (list caml-error-regexp 1 2)
- compilation-error-regexp-alist))))
+ (progn
+ (or (assoc caml-error-regexp
+ compilation-error-regexp-alist)
+ (setq compilation-error-regexp-alist
+ (cons (list caml-error-regexp 1 2)
+ compilation-error-regexp-alist)))
+ (or (assoc caml-error-regexp-newstyle
+ compilation-error-regexp-alist)
+ (setq compilation-error-regexp-alist
+ (cons (list caml-error-regexp-newstyle 1 '(2 . 4) '(3 . 5))
+ compilation-error-regexp-alist)))))
;; A regexp to extract the range info
@@ -1194,6 +1208,11 @@ Used to distinguish it from toplevel let construct.")
(defconst caml-kwop-regexps (make-vector 9 nil)
"Array of regexps representing caml keywords of different priorities.")
+(defun caml-in-shebang-line ()
+ (save-excursion
+ (beginning-of-line)
+ (and (= 1 (point)) (looking-at "#!"))))
+
(defun caml-in-expr-p ()
(let ((pos (point)) (in-expr t))
(caml-find-kwop
@@ -1201,6 +1220,8 @@ Used to distinguish it from toplevel let construct.")
caml-matching-kw-regexp "\\|"
(aref caml-kwop-regexps caml-max-indent-priority)))
(cond
+ ; special case for #! at beginning of file
+ ((caml-in-shebang-line) (setq in-expr nil))
; special case for ;;
((and (> (point) 1) (= (preceding-char) ?\;) (= (following-char) ?\;))
(setq in-expr nil))