summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2003-07-23 14:20:33 +0000
committerDamien Doligez <damien.doligez-inria.fr>2003-07-23 14:20:33 +0000
commitbdda8e194ac8deffe1537ff2e95f9ad8793a6cb0 (patch)
tree1f420984bd73cb01bb047706ed9e343b44b34648 /emacs
parentc4fc5cf1f0ff9f2e21d2ead5df241da50e1523ac (diff)
downloadocaml-bdda8e194ac8deffe1537ff2e95f9ad8793a6cb0.tar.gz
integration de caml-types a caml.el
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5725 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'emacs')
-rw-r--r--emacs/Makefile3
-rw-r--r--emacs/caml-types.el87
-rw-r--r--emacs/caml.el2
3 files changed, 43 insertions, 49 deletions
diff --git a/emacs/Makefile b/emacs/Makefile
index ab0dbd2b44..7a1b70b6e5 100644
--- a/emacs/Makefile
+++ b/emacs/Makefile
@@ -4,7 +4,7 @@ include ../config/Makefile
# Files to install
FILES= caml-font.el caml-hilit.el caml.el camldebug.el \
- inf-caml.el caml-compat.el caml-help.el
+ inf-caml.el caml-compat.el caml-help.el caml-types.el
# Where to install. If empty, automatically determined.
#EMACSDIR=
@@ -21,6 +21,7 @@ COMPILECMD=(progn \
(byte-compile-file "caml.el") \
(byte-compile-file "inf-caml.el") \
(byte-compile-file "caml-help.el") \
+ (byte-compile-file "caml-types.el") \
(byte-compile-file "camldebug.el"))
install:
diff --git a/emacs/caml-types.el b/emacs/caml-types.el
index 386e5ba19a..277d8e6b65 100644
--- a/emacs/caml-types.el
+++ b/emacs/caml-types.el
@@ -12,39 +12,8 @@
;(* $Id$ *)
-; WARNING:
-; This code is experimental. Everything may change at any time.
; An emacs-lisp complement to the "-dtypes" option of ocamlc and ocamlopt.
-; Load this file in your emacs, then C-c C-t will show you the
-; type of the expression (or pattern) that contains the cursor.
-; The expression is highlighted in the current buffer.
-; The type is highlighted in "foo.annot" (if your file is "foo.ml"),
-; which is convenient when the type doesn't fit on a line.
-
-
-; Hints on using the type display:
-
-; . If you want the type of an identifier, put the cursor in any
-; occurrence of this identifier (as expression or as pattern) and
-; type C-c C-t
-; . If you want the result type of a function application, put the
-; cursor at the first space after the function name
-; . If you want the type of a list, put the cursor on a bracket,
-; or on a semicolon, or on the :: constructor
-; . Even if type checking fails, you can still look at the types
-; in the file, up to where the type checker failed.
-; . To get rid of the highlighting, put the cursor in a comment
-; and type C-c C-t.
-; . The mark in the foo.annot file is set to the beginning of the
-; type, so you can type C-x C-x in that file to view the type.
-
-
-
-; TO DO:
-; - make emacs scroll the foo.annot file to show the type
-; - (?) integrate this file into caml.el
-
; Format of the *.annot files:
@@ -73,9 +42,6 @@
; For the moment, the only possible keyword is "type".
-; (global-set-key "\C-c\C-t" 'caml-types-show-type)
-
-
(let* ((caml-types-filename-re "\"\\(\\([^\\\"]\\|\\\\.\\)*\\)\"")
(caml-types-number-re "\\([0-9]*\\)")
(caml-types-position-re
@@ -92,8 +58,21 @@
(overlay-put caml-types-type-ovl 'face 'region)
(defun caml-types-show-type ()
- "Highlight the smallest expression that contains the cursor,
- and display its type in the minibuffer."
+ "Show the type of expression or pattern at point.
+ The smallest expression or pattern that contains point is
+ temporarily highlighted. Its type is highlighted in the .annot
+ file and the mark is set to the beginning of the type.
+ The type is also displayed in the mini-buffer.
+
+ Hints on using the type display:
+ . If you want the type of an identifier, put point within any
+ occurrence of this identifier.
+ . If you want the result type of a function application, put point
+ at the first space after the function name.
+ . If you want the type of a list, put point on a bracket, on a
+ semicolon, or on the :: constructor.
+ . Even if type checking fails, you can still look at the types
+ in the file, up to where the type checker failed."
(interactive)
(let* ((target-buf (current-buffer))
(target-file (file-name-nondirectory (buffer-file-name)))
@@ -114,9 +93,9 @@
target-bol target-cnum)))
(if (null loc)
(progn
- (move-overlay caml-types-expr-ovl 1 1)
- (move-overlay caml-types-type-ovl 1 1)
- (message "The cursor is not within a typechecked expression or pattern."))
+ (delete-overlay caml-types-expr-ovl)
+ (delete-overlay caml-types-type-ovl)
+ (message "Point is not within a typechecked expression or pattern."))
(let ((left (caml-types-get-pos target-buf (nth 0 loc) (nth 1 loc)))
(right (caml-types-get-pos target-buf
(nth 2 loc) (nth 3 loc))))
@@ -127,24 +106,18 @@
(move-overlay caml-types-type-ovl (match-beginning 1) (match-end 1)
type-buf)
(message (format "type: %s" (match-string 1)))
- ; *** this doesn't seem to work, I don't know why...
- ; *** (goto-char type-point)
- ; *** workaround: set the mark instead
- (set-mark (match-beginning 1))
- )))
+ (set-mark (match-beginning 1)))))
(let
((window (get-buffer-window type-buf))
(this-window (selected-window)))
-
(if window
(progn
(select-window window)
(goto-char (mark))
(select-window this-window))))
(unwind-protect
- (sit-for 3)
- (delete-overlay caml-types-expr-ovl))
- )))
+ (sit-for 60)
+ (delete-overlay caml-types-expr-ovl)))))
(defun caml-types-date< (date1 date2)
(or (< (car date1) (car date2))
@@ -207,3 +180,21 @@
(set-buffer buf)
(toggle-read-only 1))
buf)))
+
+
+;; bindings
+
+(and
+ (boundp 'caml-mode-map)
+ (keymapp caml-mode-map)
+ (progn
+ (define-key caml-mode-map [?\C-c?\C-t] 'caml-types-show-type)
+ (let ((map (lookup-key caml-mode-map [menu-bar caml])))
+ (and
+ (keymapp map)
+ (progn
+ (define-key map [separator-types] '("---"))
+ (define-key map [show-type]
+ '("Show type at point" . caml-types-show-type )))))))
+
+(provide 'caml-types)
diff --git a/emacs/caml.el b/emacs/caml.el
index 09df4809d6..752db2deba 100644
--- a/emacs/caml.el
+++ b/emacs/caml.el
@@ -1835,6 +1835,8 @@ with prefix arg, indent that many phrases starting with the current phrase."
(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t)
+(load "caml-types")
+
;;; caml.el ends here
(provide 'caml)