branch: externals/caml
commit f45af82c52c1e12edd40a0c37280bcd62e2181e7
Author: Didier Rémy <[email protected]>
Commit: Didier Rémy <[email protected]>
- Fixed bugs + improved caml-help.el
- Added caml-set-compile-command hook to caml-mode-hook.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5360
f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
---
caml-font.el | 2 +-
caml-help.el | 78 +++++++++++++++++++++++++++++++++++++++++-------------------
caml.el | 15 ++++++++++++
3 files changed, 69 insertions(+), 26 deletions(-)
diff --git a/caml-font.el b/caml-font.el
index aca7894..4309ed8 100644
--- a/caml-font.el
+++ b/caml-font.el
@@ -94,7 +94,7 @@
caml-font-lock-keywords))
;; font-lock commands are similar for caml-mode and inferior-caml-mode
-(setq caml-mode-hook
+(add-hook 'caml-mode-hook
'(lambda ()
(cond
((fboundp 'global-font-lock-mode)
diff --git a/caml-help.el b/caml-help.el
index 12687ab..9326532 100644
--- a/caml-help.el
+++ b/caml-help.el
@@ -33,12 +33,12 @@
;; variables to be customized
(defvar ocaml-lib-path 'lazy
- "Path for ocaml lib sources (mli files)
+ "Path list for ocaml lib sources (mli files)
'lazy means ask ocaml to find it for your at first use.")
(defun ocaml-lib-path ()
"Computes if necessary and returns the path for ocaml libs"
- (if (listp 'ocaml-lib-path) nil
+ (if (listp ocaml-lib-path) nil
(setq ocaml-lib-path
(split-string
(shell-command-to-string
@@ -51,8 +51,8 @@
"c")))
(and (file-executable-p file)
(concat file " -where"))))
- "ocamlc -where"))))
- ocaml-lib-path))
+ "ocamlc -where")))))
+ ocaml-lib-path)
@@ -62,7 +62,9 @@
(concat (capitalize (substring s 0 1)) (substring s 1)))
(defun ocaml-uncapitalize (s)
- (concat (downcase (substring s 0 1)) (substring s 1)))
+ (if (> (length s) 0)
+ (concat (downcase (substring s 0 1)) (substring s 1))
+ s))
(defun iter (f l) (while (consp l) (apply f (list (car l))) (setq l (cdr l))))
@@ -111,8 +113,23 @@
(setq files (cdr files)))
modules))
+(defun ocaml-add-path (dir &optional path)
+ "Extend ocaml-module-alist with modules of DIR relative to PATH"
+ (interactive "D")
+ (let* ((old (ocaml-lib-path))
+ (new
+ (if (file-name-absolute-p dir) dir
+ (concat
+ (or (find-if '(lambda (p) (file-directory-p (concat p "/" dir)))
+ (cons default-directory old))
+ (error "Directory not found"))
+ "/" dir))))
+ (setq ocaml-lib-path (cons (car old) (cons new (cdr old))))
+ (setq ocaml-module-alist
+ (ocaml-add-mli-modules (ocaml-module-alist) 'lib new))))
+
(defun ocaml-module-alist ()
- "Call by need value of valriable ocaml-module-alist"
+ "Call by need value of variable ocaml-module-alist"
(if (listp ocaml-module-alist)
nil
;; build list of mli files
@@ -252,10 +269,10 @@ with an optional non-nil argument.
(let ((module) (entry))
(if (looking-at "[ \n]") (skip-chars-backward " "))
(if (re-search-backward
- "[^A-Za-z0-9_.']\\([A-Za-z0-9_']*[.]\\)*[A-Za-z0-9_']*\\="
+
"\\([^A-Za-z0-9_.']\\|\\`\\)\\([A-Za-z0-9_']*[.]\\)*[A-Za-z0-9_']*\\="
(- (point) 100) t)
(progn
- (forward-char 1)
+ (or (looking-at "\\`[A-Za-z)-9_.]") (forward-char 1))
(if (looking-at "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)[.]")
(progn
(setq module (cons (match-beginning 1) (match-end 1)))
@@ -528,7 +545,7 @@ command. An entry may be an info module or a complete file
name."
(if (member symbol (ocaml-module-symbols (car list)))
(setq collect (cons (car list) collect)))
(setq list (cdr list)))
- collect
+ (nreverse collect)
))
(defun ocaml-buffer-substring (region)
@@ -554,7 +571,6 @@ current buffer using \\[ocaml-qualified-identifier]."
(cond
(location
; (view-file
- (message "FOO")
(view-file-other-window
(concat location (ocaml-uncapitalize module) ".mli"))
(bury-buffer (current-buffer)))
@@ -562,17 +578,24 @@ current buffer using \\[ocaml-qualified-identifier]."
(t (error "No help for module %s" module))))
))
(if (stringp entry)
- (let ((here (point)))
+ (let ((here (point))
+ (case-fold-search nil))
(goto-char (point-min))
- (or (re-search-forward
- (concat "\\(val\\|exception\\|external\\|[|{;]\\) +"
- (regexp-quote entry))
- (point-max) t)
- (search-forward entry (point-max) t)
- (progn
- (message "Help for entry %s not found in module %s"
- entry module)
- (goto-char here)))))
+ (if (or (re-search-forward
+ (concat "\\(val\\|exception\\|external\\|[|{;]\\) +"
+ (regexp-quote entry))
+ (point-max) t)
+ (progn
+ (if (window-live-p window) (select-window window))
+ (error "Entry %S not found in module %S"
+ entry module))
+ ;; (search-forward entry (point-max) t)
+ )
+ (recenter 1)
+ (progn
+ (message "Help for entry %s not found in module %s"
+ entry module)
+ (goto-char here)))))
(if (window-live-p window) (select-window window))
))
@@ -599,8 +622,8 @@ of using contextual values.
(or (and
(setq module
(completing-read "Module: " (ocaml-module-alist)
- nil t "" (cons 'hist 0))))
- (not (string-equal module ""))
+ nil t "" (cons 'hist 0)))
+ (not (string-equal module "")))
(error "Quit"))
(let ((symbols
(mapcar 'list
@@ -618,7 +641,7 @@ of using contextual values.
(let ((modules
(or (ocaml-find-module entry (ocaml-visible-modules))
(ocaml-find-module entry)))
- (hist))
+ (hist) (default))
(cond
((null modules)
(error "No module found for entry %s" entry))
@@ -626,8 +649,13 @@ of using contextual values.
(caar modules))
(t
(setq hist (mapcar 'car modules))
- (completing-read "Module: " modules nil t
- "" (cons 'hist 0)))
+ (setq default (car hist))
+ (setq module
+ (completing-read
+ (concat "Module: "
+ (and default (concat "[" default "] ")))
+ modules nil t "" (cons 'hist 0)))
+ (if (string-equal module "") default module))
))))
))
(message "Help for %s%s%s" module (if entry "." "") (or entry ""))
diff --git a/caml.el b/caml.el
index 710df90..05e722f 100644
--- a/caml.el
+++ b/caml.el
@@ -424,6 +424,10 @@ have caml-electric-indent on, which see.")
(if (and (boundp 'running-xemacs) running-xemacs) nil
(require 'imenu)))
+;;
+(defvar caml-mode-hook nil
+ "Hook for caml-mode")
+
(defun caml-mode ()
"Major mode for editing Caml code.
@@ -484,6 +488,17 @@ have caml-electric-indent on, which see.")
(caml-show-imenu)))
(run-hooks 'caml-mode-hook))
+(defun caml-set-compile-command ()
+ (interactive)
+ (unless (or (file-exists-p "makefile")
+ (file-exists-p "Makefile"))
+ (make-local-variable 'compile-command)
+ (setq compile-command
+ (concat "ocamlc -c "
+ (file-name-nondirectory buffer-file-name)))))
+
+(add-hook 'caml-mode-hook 'caml-set-compile-command)
+
;;; Auxiliary function. Garrigue 96-11-01.
(defun caml-find-alternate-file ()