2004-08-20 10:04:35 -07:00
|
|
|
;(***********************************************************************)
|
|
|
|
;(* *)
|
|
|
|
;(* Objective Caml *)
|
|
|
|
;(* *)
|
|
|
|
;(* Didier Remy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
;(* *)
|
|
|
|
;(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
;(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
;(* under the terms of the GNU General Public License. *)
|
|
|
|
;(* *)
|
|
|
|
;(***********************************************************************)
|
|
|
|
|
|
|
|
;(* $Id$ *)
|
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
;; caml-info.el --- contextual completion and help to caml-mode
|
|
|
|
|
|
|
|
;; Didier Remy, November 2001.
|
|
|
|
|
|
|
|
;; This provides two functions completion and help
|
2001-12-03 00:59:32 -08:00
|
|
|
;; look for caml-complete and caml-help
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;; This is a preliminary version.
|
|
|
|
;;
|
|
|
|
;; Possible improvements?
|
|
|
|
;; - dump some databaes: Info, Lib, ...
|
|
|
|
;; - accept a search path for local libraries instead of current dir
|
|
|
|
;; (then distinguish between different modules lying in different
|
2010-01-22 04:48:24 -08:00
|
|
|
;; directories)
|
2001-11-27 03:05:33 -08:00
|
|
|
;; - improve the construction for info files.
|
|
|
|
;;
|
2010-01-22 04:48:24 -08:00
|
|
|
;; Abstract over
|
2001-11-27 03:05:33 -08:00
|
|
|
;; - the viewing method and the database, so that the documentation for
|
2010-01-22 04:48:24 -08:00
|
|
|
;; and identifier could be search in
|
2001-11-27 03:05:33 -08:00
|
|
|
;; * info / html / man / mli's sources
|
|
|
|
;; * viewed in emacs or using an external previewer.
|
|
|
|
;;
|
|
|
|
;; Take all identifiers (labels, Constructors, exceptions, etc.)
|
2010-01-22 04:48:24 -08:00
|
|
|
;;
|
2001-11-27 03:05:33 -08:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
2003-07-28 23:54:28 -07:00
|
|
|
(eval-and-compile
|
2010-01-22 04:48:24 -08:00
|
|
|
(if (and (boundp 'running-xemacs) running-xemacs)
|
2003-07-28 23:54:28 -07:00
|
|
|
(require 'caml-xemacs)
|
|
|
|
(require 'caml-emacs)))
|
2003-07-28 11:06:49 -07:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
;; Loading or building databases.
|
2010-01-22 04:48:24 -08:00
|
|
|
;;
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
;; variables to be customized
|
|
|
|
|
2001-12-07 09:01:59 -08:00
|
|
|
(defvar ocaml-lib-path 'lazy
|
2002-12-27 10:24:33 -08:00
|
|
|
"Path list for ocaml lib sources (mli files)
|
2001-12-07 09:01:59 -08:00
|
|
|
|
|
|
|
'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"
|
2002-12-27 10:24:33 -08:00
|
|
|
(if (listp ocaml-lib-path) nil
|
2001-12-07 09:01:59 -08:00
|
|
|
(setq ocaml-lib-path
|
2002-06-27 06:12:03 -07:00
|
|
|
(split-string
|
|
|
|
(shell-command-to-string
|
|
|
|
(or
|
|
|
|
(and (boundp 'inferior-caml-program)
|
|
|
|
(string-match "\\([^ ]*/ocaml\\)\\( \\|$\\)"
|
|
|
|
inferior-caml-program)
|
|
|
|
(let ((file
|
|
|
|
(concat (match-string 1 inferior-caml-program)
|
|
|
|
"c")))
|
|
|
|
(and (file-executable-p file)
|
|
|
|
(concat file " -where"))))
|
2002-12-27 10:24:33 -08:00
|
|
|
"ocamlc -where")))))
|
|
|
|
ocaml-lib-path)
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
;; General purpose auxiliary functions
|
|
|
|
|
|
|
|
(defun ocaml-capitalize (s)
|
|
|
|
(concat (capitalize (substring s 0 1)) (substring s 1)))
|
|
|
|
|
|
|
|
(defun ocaml-uncapitalize (s)
|
2002-12-27 10:24:33 -08:00
|
|
|
(if (> (length s) 0)
|
|
|
|
(concat (downcase (substring s 0 1)) (substring s 1))
|
|
|
|
s))
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
(defun iter (f l) (while (consp l) (apply f (list (car l))) (setq l (cdr l))))
|
|
|
|
|
|
|
|
(defun ocaml-find-files (path filter &optional depth split)
|
|
|
|
(let* ((path-string
|
|
|
|
(if (stringp path)
|
|
|
|
(if (file-directory-p path) path nil)
|
|
|
|
(mapconcat '(lambda (d) (if (file-directory-p d) d))
|
2010-01-22 04:48:24 -08:00
|
|
|
path " ")))
|
2001-11-27 03:05:33 -08:00
|
|
|
(command
|
|
|
|
(and path-string
|
|
|
|
(concat "find " path-string
|
|
|
|
" '(' " filter " ')' "
|
|
|
|
(if depth (concat " -maxdepth " (int-to-string depth)))
|
2010-01-22 04:48:24 -08:00
|
|
|
(if split nil " -printf '%\p '")
|
2001-11-27 03:05:33 -08:00
|
|
|
)))
|
|
|
|
(files
|
|
|
|
(and command (shell-command-to-string command))))
|
2010-01-22 04:48:24 -08:00
|
|
|
(if (and split (stringp files)) (split-string files "\n") files)
|
2001-11-27 03:05:33 -08:00
|
|
|
))
|
|
|
|
|
|
|
|
;; Specialized auxiliary functions
|
|
|
|
|
|
|
|
|
|
|
|
;; Global table of modules contents of modules loaded lazily.
|
|
|
|
|
|
|
|
(defvar ocaml-module-alist 'lazy
|
2010-01-22 04:48:24 -08:00
|
|
|
"A-list of modules with how and where to find help information.
|
2001-11-27 03:05:33 -08:00
|
|
|
'delay means non computed yet")
|
|
|
|
|
|
|
|
(defun ocaml-add-mli-modules (modules tag &optional path)
|
|
|
|
(let ((files
|
2001-12-07 09:01:59 -08:00
|
|
|
(ocaml-find-files (or path (ocaml-lib-path))
|
2001-11-27 03:05:33 -08:00
|
|
|
"-type f -name '*.mli'" 1 t)))
|
|
|
|
(while (consp files)
|
|
|
|
(if (string-match "\\([^/]*\\).mli" (car files))
|
|
|
|
(let* ((module (ocaml-capitalize (match-string 1 (car files))))
|
|
|
|
(dir (file-name-directory (car files)))
|
2001-12-07 09:01:59 -08:00
|
|
|
(dirp (member dir (ocaml-lib-path))))
|
2001-11-27 03:05:33 -08:00
|
|
|
(if (and (consp dirp) (string-equal dir (car dirp)))
|
|
|
|
(setq dir (car dirp)))
|
|
|
|
(if (assoc module modules) nil
|
|
|
|
(setq modules
|
|
|
|
(cons (cons module (cons (cons tag dir) 'lazy)) modules))
|
|
|
|
)))
|
|
|
|
(setq files (cdr files)))
|
|
|
|
modules))
|
|
|
|
|
2002-12-27 10:24:33 -08:00
|
|
|
(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))))
|
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
(defun ocaml-module-alist ()
|
2002-12-27 10:24:33 -08:00
|
|
|
"Call by need value of variable ocaml-module-alist"
|
2001-11-27 03:05:33 -08:00
|
|
|
(if (listp ocaml-module-alist)
|
|
|
|
nil
|
|
|
|
;; build list of mli files
|
|
|
|
(setq ocaml-module-alist (ocaml-add-mli-modules nil 'lib))
|
|
|
|
;; dumping information ? TODO
|
|
|
|
)
|
|
|
|
ocaml-module-alist)
|
|
|
|
|
|
|
|
(defun ocaml-get-or-make-module (module &optional tag)
|
|
|
|
(let ((info (assoc module (ocaml-module-alist))))
|
|
|
|
(if info nil
|
|
|
|
(setq info (cons module (cons (cons 'local default-directory) 'lazy)))
|
|
|
|
(setq ocaml-module-alist (cons info ocaml-module-alist))
|
|
|
|
)
|
|
|
|
info))
|
|
|
|
|
|
|
|
;; Symbols of module are lazily computed
|
|
|
|
|
|
|
|
(defun ocaml-module-filename (module)
|
2002-06-27 06:12:03 -07:00
|
|
|
(let ((module (ocaml-uncapitalize module)) (name))
|
|
|
|
(if (file-exists-p (setq name (concat module ".mli"))) nil
|
|
|
|
(let ((tmp (ocaml-lib-path)))
|
|
|
|
(while (consp tmp)
|
|
|
|
(setq name (concat (car tmp) "/" module ".mli"))
|
|
|
|
(if (file-exists-p name) (setq tmp nil)
|
|
|
|
(setq name nil)))))
|
2001-11-27 03:05:33 -08:00
|
|
|
name))
|
|
|
|
|
|
|
|
(defun ocaml-module-symbols (module-info)
|
|
|
|
(let* ((module (car module-info))
|
|
|
|
(tail (and module-info (cdr module-info)))
|
|
|
|
(tag (caar tail))
|
|
|
|
(dir (cdar tail))
|
|
|
|
(file)
|
|
|
|
(alist))
|
|
|
|
(if (listp (cdr tail))
|
|
|
|
(cdr tail)
|
|
|
|
(if (equal tag 'info)
|
|
|
|
(setq dir (car ocaml-lib-path)) ; XXX to be fixed
|
|
|
|
)
|
2003-07-07 01:46:23 -07:00
|
|
|
(setq file (concat dir "/" (ocaml-uncapitalize module) ".mli"))
|
2001-11-27 03:05:33 -08:00
|
|
|
(message file)
|
|
|
|
(save-window-excursion
|
2001-12-03 00:59:32 -08:00
|
|
|
(set-buffer (get-buffer-create "*caml-help*"))
|
2001-11-27 03:05:33 -08:00
|
|
|
(if (and file (file-exists-p file))
|
|
|
|
(progn
|
|
|
|
(message "Scanning module %s" file)
|
|
|
|
(insert-file-contents file))
|
|
|
|
(message "Module %s not found" module))
|
|
|
|
(while (re-search-forward
|
2003-07-07 01:46:23 -07:00
|
|
|
"\\([ \t]*val\\|let\\|external\\| [|]\\) \\([a-zA-Z_0-9'][a-zA-Z_0-9']*\\)\\|^ *[{]* \\([a-z_][A-Za-z_0-9]*\\) : [^;\n][^;\n]*;"
|
|
|
|
(point-max) 'move)
|
|
|
|
(pop-to-buffer (current-buffer))
|
|
|
|
(setq alist (cons (or (match-string 2) (match-string 3)) alist)))
|
2001-11-27 03:05:33 -08:00
|
|
|
(erase-buffer)
|
|
|
|
)
|
|
|
|
(setcdr tail alist)
|
|
|
|
alist)
|
|
|
|
))
|
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
;; Local list of visible modules.
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
(defvar ocaml-visible-modules 'lazy
|
|
|
|
"A-list of open modules, local to every file.")
|
|
|
|
(make-variable-buffer-local 'ocaml-visible-modules)
|
|
|
|
(defun ocaml-visible-modules ()
|
|
|
|
(if (listp ocaml-visible-modules) nil
|
|
|
|
(progn
|
|
|
|
(setq ocaml-visible-modules
|
|
|
|
(list (ocaml-get-or-make-module "Pervasives")))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward "^ *open *\\([A-Z][a-zA-Z'_0-9]*\\)"
|
|
|
|
(point-max) t)
|
|
|
|
(let ((module (match-string 1)))
|
2002-11-05 23:59:25 -08:00
|
|
|
(if (assoc module ocaml-visible-modules) nil
|
2001-11-27 03:05:33 -08:00
|
|
|
(setq ocaml-visible-modules
|
|
|
|
(cons (ocaml-get-or-make-module module)
|
|
|
|
ocaml-visible-modules)))))
|
|
|
|
)))
|
|
|
|
ocaml-visible-modules)
|
|
|
|
|
2002-11-05 23:59:25 -08:00
|
|
|
(defun ocaml-open-module (arg)
|
|
|
|
"*Make module of name ARG visible whe ARG is a string.
|
|
|
|
When call interactively, make completion over known modules."
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (stringp arg))
|
2003-07-28 11:06:49 -07:00
|
|
|
(let ((modules (ocaml-module-alist)))
|
2002-11-05 23:59:25 -08:00
|
|
|
(setq arg
|
|
|
|
(completing-read "Open module: " modules))))
|
|
|
|
(if (and (stringp arg) (not (equal arg "")))
|
|
|
|
(progn
|
|
|
|
(if (assoc arg (ocaml-visible-modules))
|
|
|
|
(ocaml-close-module arg))
|
|
|
|
(setq ocaml-visible-modules
|
|
|
|
(cons (ocaml-get-or-make-module arg) (ocaml-visible-modules)))
|
|
|
|
))
|
2002-11-07 06:05:53 -08:00
|
|
|
(message "%S" (mapcar 'car (ocaml-visible-modules))))
|
2002-11-05 23:59:25 -08:00
|
|
|
|
|
|
|
(defun ocaml-close-module (arg)
|
2010-01-22 04:48:24 -08:00
|
|
|
"*Close module of name ARG when ARG is a string.
|
|
|
|
When call interactively, make completion over visible modules.
|
2002-11-05 23:59:25 -08:00
|
|
|
Otherwise if ARG is true, close all modules and reset to default. "
|
|
|
|
(interactive "P")
|
|
|
|
(if (= (prefix-numeric-value arg) 4)
|
|
|
|
(setq ocaml-visible-modules 'lazy)
|
2003-07-28 11:06:49 -07:00
|
|
|
(let* ((modules (ocaml-visible-modules)))
|
2003-07-07 01:46:23 -07:00
|
|
|
(if (null modules) (error "No visible module to close"))
|
2002-11-05 23:59:25 -08:00
|
|
|
(unless (stringp arg)
|
|
|
|
(setq arg
|
|
|
|
(completing-read
|
|
|
|
(concat "Close module [" (caar modules) "] : ")
|
|
|
|
modules))
|
|
|
|
(if (equal arg "") (setq arg (caar modules))))
|
|
|
|
(setq ocaml-visible-modules
|
|
|
|
(remove-if '(lambda (m) (equal (car m) arg))
|
|
|
|
ocaml-visible-modules))
|
|
|
|
))
|
2002-11-07 06:05:53 -08:00
|
|
|
(message "%S" (mapcar 'car (ocaml-visible-modules))))
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2002-11-05 23:59:25 -08:00
|
|
|
|
2001-12-03 00:59:32 -08:00
|
|
|
;; Look for identifiers around point
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2001-12-07 09:01:59 -08:00
|
|
|
(defun ocaml-qualified-identifier (&optional show)
|
2010-01-22 04:48:24 -08:00
|
|
|
"Search for a qualified identifier (Path. entry) around point.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
|
|
|
Entry may be nil.
|
2010-01-22 04:48:24 -08:00
|
|
|
Currently, the path may only be nil or a single Module.
|
|
|
|
For paths is of the form Module.Path', it returns Module
|
|
|
|
and always nil for entry.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
If defined Module and Entry are represented by a region in the buffer,
|
|
|
|
and are nil otherwise.
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
For debugging purposes, it returns the string Module.entry if called
|
|
|
|
with an optional non-nil argument.
|
2001-12-07 09:01:59 -08:00
|
|
|
"
|
2001-12-03 00:59:32 -08:00
|
|
|
(save-excursion
|
|
|
|
(let ((module) (entry))
|
2010-01-22 04:48:24 -08:00
|
|
|
(if (looking-at "[ \n]") (skip-chars-backward " "))
|
2001-12-03 00:59:32 -08:00
|
|
|
(if (re-search-backward
|
2002-12-27 10:24:33 -08:00
|
|
|
"\\([^A-Za-z0-9_.']\\|\\`\\)\\([A-Za-z0-9_']*[.]\\)*[A-Za-z0-9_']*\\="
|
2001-12-03 00:59:32 -08:00
|
|
|
(- (point) 100) t)
|
|
|
|
(progn
|
2002-12-27 10:24:33 -08:00
|
|
|
(or (looking-at "\\`[A-Za-z)-9_.]") (forward-char 1))
|
2001-12-07 09:01:59 -08:00
|
|
|
(if (looking-at "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)[.]")
|
2001-12-03 00:59:32 -08:00
|
|
|
(progn
|
|
|
|
(setq module (cons (match-beginning 1) (match-end 1)))
|
|
|
|
(goto-char (match-end 0))))
|
2003-07-07 01:46:23 -07:00
|
|
|
(if (looking-at "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)\\>")
|
2001-12-07 09:01:59 -08:00
|
|
|
(setq entry (cons (match-beginning 1) (match-end 1))))))
|
|
|
|
(if show
|
|
|
|
(concat
|
|
|
|
(and module (buffer-substring (car module) (cdr module)))
|
|
|
|
"."
|
|
|
|
(and entry (buffer-substring (car entry) (cdr entry))))
|
2001-12-03 00:59:32 -08:00
|
|
|
(cons module entry))
|
2001-12-07 09:01:59 -08:00
|
|
|
)))
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
;; completion around point
|
|
|
|
|
|
|
|
(defun ocaml-completion (pattern module)
|
|
|
|
(let ((list
|
|
|
|
(or
|
|
|
|
(and module
|
2010-01-22 04:48:24 -08:00
|
|
|
(list
|
2001-11-27 03:05:33 -08:00
|
|
|
(or (assoc module (ocaml-module-alist))
|
|
|
|
(error "Unknown module %s" module))))
|
|
|
|
(ocaml-visible-modules))))
|
|
|
|
(message "Completion from %s" (mapconcat 'car list " "))
|
|
|
|
(if (null pattern)
|
|
|
|
(apply 'append (mapcar 'ocaml-module-symbols list))
|
|
|
|
(let ((pat (concat "^" (regexp-quote pattern))) (res))
|
|
|
|
(iter
|
|
|
|
'(lambda (l)
|
|
|
|
(iter '(lambda (x)
|
|
|
|
(if (string-match pat (car l))
|
|
|
|
(if (member x res) nil (setq res (cons x res)))))
|
|
|
|
(ocaml-module-symbols l)))
|
|
|
|
list)
|
|
|
|
res)
|
|
|
|
)))
|
|
|
|
|
2001-12-03 00:59:32 -08:00
|
|
|
(defun caml-complete (arg)
|
2010-01-22 04:48:24 -08:00
|
|
|
"Does completion for OCaml identifiers qualified.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
It attemps to recognize an qualified identifier Module . entry
|
2002-11-05 23:59:25 -08:00
|
|
|
around point using function \\[ocaml-qualified-identifier].
|
2001-12-07 09:01:59 -08:00
|
|
|
|
|
|
|
If Module is defined, it does completion for identifier in Module.
|
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
If Module is undefined, it does completion in visible modules.
|
|
|
|
Then, if completion fails, it does completion among all modules
|
2001-12-10 05:22:10 -08:00
|
|
|
where identifier is defined."
|
2001-11-27 03:05:33 -08:00
|
|
|
(interactive "p")
|
2003-07-28 11:06:49 -07:00
|
|
|
(let* ((module-entry (ocaml-qualified-identifier)) (entry)
|
2010-01-22 04:48:24 -08:00
|
|
|
(module)
|
2001-11-27 03:05:33 -08:00
|
|
|
(beg) (end) (pattern))
|
|
|
|
(if (car module-entry)
|
2002-06-27 06:12:03 -07:00
|
|
|
(progn
|
|
|
|
(setq module
|
|
|
|
(buffer-substring (caar module-entry) (cdar module-entry)))
|
|
|
|
(or (assoc module (ocaml-module-alist))
|
|
|
|
(and (setq module
|
|
|
|
(completing-read "Module: " (ocaml-module-alist)
|
|
|
|
nil nil module))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (caar module-entry))
|
|
|
|
(delete-region (caar module-entry) (cdar module-entry))
|
|
|
|
(insert module) t)
|
|
|
|
(setq module-entry (ocaml-qualified-identifier))
|
|
|
|
(car module-entry)
|
|
|
|
(progn (setq entry (cdr module-entry)) t))
|
|
|
|
(error "Unknown module %s" module))))
|
2001-11-27 03:05:33 -08:00
|
|
|
(if (consp (cdr module-entry))
|
2010-01-22 04:48:24 -08:00
|
|
|
(progn
|
2001-11-27 03:05:33 -08:00
|
|
|
(setq beg (cadr module-entry))
|
|
|
|
(setq end (cddr module-entry)))
|
|
|
|
(if (and module
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (cdar module-entry))
|
|
|
|
(looking-at " *[.]")))
|
|
|
|
(progn
|
|
|
|
(setq beg (match-end 0))
|
|
|
|
(setq end beg))))
|
|
|
|
(if (not (and beg end))
|
|
|
|
(error "Did not find anything to complete around point")
|
2002-06-27 06:12:03 -07:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
(setq pattern (buffer-substring beg end))
|
2003-07-28 11:06:49 -07:00
|
|
|
(let* ((all-completions (ocaml-completion pattern module))
|
2001-11-27 03:05:33 -08:00
|
|
|
(completion
|
|
|
|
(try-completion pattern (mapcar 'list all-completions))))
|
|
|
|
(cond ((eq completion t))
|
|
|
|
|
|
|
|
((null completion)
|
|
|
|
(let*
|
|
|
|
((modules (ocaml-find-module pattern))
|
2002-11-05 23:59:25 -08:00
|
|
|
(visible (intersection modules (ocaml-visible-modules)))
|
2002-06-27 06:12:03 -07:00
|
|
|
(hist)
|
2001-11-27 03:05:33 -08:00
|
|
|
(module
|
|
|
|
(cond
|
|
|
|
((null modules)
|
|
|
|
nil)
|
|
|
|
((equal (length modules) 1)
|
|
|
|
(caar modules))
|
2002-11-05 23:59:25 -08:00
|
|
|
((equal (length visible) 1)
|
|
|
|
(caar visible))
|
2001-11-27 03:05:33 -08:00
|
|
|
(t
|
|
|
|
(setq hist (mapcar 'car modules))
|
|
|
|
(completing-read "Module: " modules nil t
|
2003-07-28 11:06:49 -07:00
|
|
|
"" (cons hist 0)))
|
2001-11-27 03:05:33 -08:00
|
|
|
)))
|
|
|
|
(if (null module)
|
|
|
|
(error "Can't find completion for \"%s\"" pattern)
|
2002-06-27 06:12:03 -07:00
|
|
|
(message "Completion found in module %s" module)
|
|
|
|
(if (and (consp module-entry) (consp (cdr module-entry)))
|
|
|
|
(delete-region (caar module-entry) end)
|
|
|
|
(delete-region beg end))
|
2001-11-27 03:05:33 -08:00
|
|
|
(insert module "." pattern))))
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
((not (string-equal pattern completion))
|
|
|
|
(delete-region beg end)
|
2003-07-07 01:46:23 -07:00
|
|
|
(goto-char beg)
|
2001-11-27 03:05:33 -08:00
|
|
|
(insert completion))
|
|
|
|
|
|
|
|
(t
|
2002-06-27 06:12:03 -07:00
|
|
|
(with-output-to-temp-buffer "*Completions*"
|
|
|
|
(display-completion-list all-completions))
|
|
|
|
))
|
2001-11-27 03:05:33 -08:00
|
|
|
))))
|
|
|
|
|
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
;; Info files (only in ocamldoc style)
|
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2002-11-05 23:59:25 -08:00
|
|
|
(defvar ocaml-info-prefix "ocaml-lib"
|
|
|
|
"Prefix of ocaml info files describing library modules.
|
2010-01-22 04:48:24 -08:00
|
|
|
Suffix .info will be added to info files.
|
2002-06-27 06:12:03 -07:00
|
|
|
Additional suffix .gz may be added if info files are compressed.
|
|
|
|
")
|
2010-01-22 04:48:24 -08:00
|
|
|
;;
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
(defun ocaml-hevea-info-add-entries (entries dir name)
|
2001-11-27 03:05:33 -08:00
|
|
|
(let*
|
2001-12-07 09:01:59 -08:00
|
|
|
((filter
|
|
|
|
(concat "-type f -regex '.*/" name
|
|
|
|
"\\(.info\\|\\)\\(-[0-9]*\\|\\)\\([.]gz\\|\\)'"
|
|
|
|
))
|
|
|
|
(section-regexp
|
|
|
|
"\\* \\(Section [1-9][0-9--]*\\)::[ \t][ \t]*Module *\\([A-Z][A-Za-z_0-9]*\\)")
|
2001-11-27 03:05:33 -08:00
|
|
|
(files (ocaml-find-files dir filter))
|
|
|
|
(command))
|
|
|
|
;; scanning info files
|
|
|
|
(if (or (null files)
|
|
|
|
(not (stringp files))
|
|
|
|
(string-match files "^ *$"))
|
|
|
|
(message "No info file found: %s." (mapconcat 'identity files " "))
|
|
|
|
(message "Scanning info files %s." files)
|
2002-06-27 06:12:03 -07:00
|
|
|
(save-window-excursion
|
|
|
|
(set-buffer (get-buffer-create "*caml-help*"))
|
|
|
|
(setq command
|
|
|
|
(concat "zcat -f " files
|
|
|
|
" | grep -e '" section-regexp "'"))
|
|
|
|
(message "Scanning files with: %s" command)
|
|
|
|
(or (shell-command command (current-buffer))
|
|
|
|
(error "Error while scanning"))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward section-regexp (point-max) t)
|
|
|
|
(let* ((module (match-string 2))
|
|
|
|
(section (match-string 1)))
|
|
|
|
;; (message "%s %s" module section)
|
|
|
|
(if (assoc module entries) nil
|
|
|
|
(setq entries
|
|
|
|
(cons (cons module (concat "(" name ")" section))
|
|
|
|
entries))
|
|
|
|
)))
|
|
|
|
(let ((buf (get-buffer "*caml-help*")))
|
|
|
|
(if buf (kill-buffer buf)))))
|
2001-11-27 03:05:33 -08:00
|
|
|
entries))
|
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
(defun ocaml-hevea-info ()
|
2010-01-22 04:48:24 -08:00
|
|
|
"The default way to create an info data base from the value
|
|
|
|
of \\[Info-default-directory-list] and the base name \\[ocaml-info-name]
|
|
|
|
of files to look for.
|
2001-12-10 05:22:10 -08:00
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
This uses info files produced by HeVeA.
|
|
|
|
"
|
2001-12-07 09:01:59 -08:00
|
|
|
(let ((collect) (seen))
|
|
|
|
(iter '(lambda (d)
|
|
|
|
(if (member d seen) nil
|
|
|
|
(setq collect
|
2002-06-27 06:12:03 -07:00
|
|
|
(ocaml-hevea-info-add-entries
|
2002-11-05 23:59:25 -08:00
|
|
|
collect d ocaml-info-prefix))
|
2001-12-07 09:01:59 -08:00
|
|
|
(setq done (cons d seen))))
|
|
|
|
Info-directory-list)
|
|
|
|
collect))
|
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
(defun ocaml-ocamldoc-info-add-entries (entries dir name)
|
2001-12-07 09:01:59 -08:00
|
|
|
(let*
|
|
|
|
((module-regexp "^Node: \\([A-Z][A-Za-z_0-9]*\\)[^ ]")
|
|
|
|
(command
|
|
|
|
(concat
|
|
|
|
"find " dir " -type f -regex '.*/" name
|
|
|
|
"\\(.info\\|\\)\\([.]gz\\|\\)' -print0"
|
2002-06-27 06:12:03 -07:00
|
|
|
" | xargs -0 zcat -f | grep '" module-regexp "'")))
|
2001-12-07 09:01:59 -08:00
|
|
|
(message "Scanning info files in %s" dir)
|
2002-06-27 06:12:03 -07:00
|
|
|
(save-window-excursion
|
|
|
|
(set-buffer (get-buffer-create "*caml-help*"))
|
|
|
|
(or (shell-command command (current-buffer)) (error "HERE"))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward module-regexp (point-max) t)
|
|
|
|
(if (equal (char-after (match-end 1)) 127)
|
|
|
|
(let* ((module (match-string 1)))
|
|
|
|
(if (assoc module entries) nil
|
|
|
|
(setq entries
|
|
|
|
(cons (cons module (concat "(" name ")" module))
|
|
|
|
entries))
|
|
|
|
))))
|
|
|
|
; (kill-buffer (current-buffer))
|
|
|
|
)
|
2001-12-07 09:01:59 -08:00
|
|
|
entries))
|
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
(defun ocaml-ocamldoc-info ()
|
2010-01-22 04:48:24 -08:00
|
|
|
"The default way to create an info data base from the value
|
|
|
|
of \\[Info-default-directory-list] and the base name \\[ocaml-info-name]
|
2002-11-05 23:59:25 -08:00
|
|
|
of files to look for.
|
2001-12-10 05:22:10 -08:00
|
|
|
|
|
|
|
This uses info files produced by ocamldoc."
|
2002-06-27 06:12:03 -07:00
|
|
|
(require 'info)
|
2001-11-27 03:05:33 -08:00
|
|
|
(let ((collect) (seen))
|
|
|
|
(iter '(lambda (d)
|
|
|
|
(if (member d seen) nil
|
|
|
|
(setq collect
|
2002-06-27 06:12:03 -07:00
|
|
|
(ocaml-ocamldoc-info-add-entries collect d
|
|
|
|
ocaml-info-prefix))
|
2001-11-27 03:05:33 -08:00
|
|
|
(setq done (cons d seen))))
|
|
|
|
Info-directory-list)
|
|
|
|
collect))
|
|
|
|
|
2002-06-27 06:12:03 -07:00
|
|
|
;; Continuing
|
|
|
|
|
2002-11-05 23:59:25 -08:00
|
|
|
(defvar ocaml-info-alist 'ocaml-ocamldoc-info
|
2010-01-22 04:48:24 -08:00
|
|
|
"A-list binding module names to info entries:
|
2002-06-27 06:12:03 -07:00
|
|
|
|
|
|
|
nil means do not use info.
|
|
|
|
|
|
|
|
A function to build the list lazily (at the first call). The result of
|
|
|
|
the function call will be assign permanently to this variable for future
|
2002-11-05 23:59:25 -08:00
|
|
|
uses. We provide two default functions \\[ocaml-info-default-function]
|
2010-01-22 04:48:24 -08:00
|
|
|
(info produced by HeVeA is the default) and \\[ocaml-info-default-function]
|
|
|
|
(info produced by ocamldoc).
|
2002-06-27 06:12:03 -07:00
|
|
|
|
|
|
|
Otherwise, this value should be an alist binding module names to info
|
2010-01-22 04:48:24 -08:00
|
|
|
entries of the form to \"(entry)section\" be taken by the \\[info]
|
2002-06-27 06:12:03 -07:00
|
|
|
command. An entry may be an info module or a complete file name."
|
|
|
|
)
|
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
(defun ocaml-info-alist ()
|
|
|
|
"Call by need value of variable ocaml-info-alist"
|
|
|
|
(cond
|
|
|
|
((listp ocaml-info-alist))
|
|
|
|
((functionp ocaml-info-alist)
|
|
|
|
(setq ocaml-info-alist (apply ocaml-info-alist nil)))
|
|
|
|
(t
|
|
|
|
(error "wrong type for ocaml-info-alist")))
|
|
|
|
ocaml-info-alist)
|
|
|
|
|
|
|
|
;; help around point
|
|
|
|
|
|
|
|
(defun ocaml-find-module (symbol &optional module-list)
|
|
|
|
(let ((list (or module-list (ocaml-module-alist)))
|
|
|
|
(collect))
|
|
|
|
(while (consp list)
|
|
|
|
(if (member symbol (ocaml-module-symbols (car list)))
|
|
|
|
(setq collect (cons (car list) collect)))
|
|
|
|
(setq list (cdr list)))
|
2002-12-27 10:24:33 -08:00
|
|
|
(nreverse collect)
|
2001-11-27 03:05:33 -08:00
|
|
|
))
|
|
|
|
|
|
|
|
(defun ocaml-buffer-substring (region)
|
2002-03-19 01:45:46 -08:00
|
|
|
(and region (buffer-substring-no-properties (car region) (cdr region))))
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
;; Help function.
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2003-07-28 11:06:49 -07:00
|
|
|
|
2003-11-28 12:14:15 -08:00
|
|
|
(defun ocaml-goto-help (&optional module entry same-window)
|
2001-11-27 03:05:33 -08:00
|
|
|
"Searches info manual for MODULE and ENTRY in MODULE.
|
|
|
|
If unspecified, MODULE and ENTRY are inferred from the position in the
|
2002-11-05 23:59:25 -08:00
|
|
|
current buffer using \\[ocaml-qualified-identifier]."
|
2001-11-27 03:05:33 -08:00
|
|
|
(interactive)
|
2003-07-07 01:46:23 -07:00
|
|
|
(let ((window (selected-window))
|
|
|
|
(info-section (assoc module (ocaml-info-alist))))
|
|
|
|
(if info-section
|
2003-07-28 23:54:28 -07:00
|
|
|
(caml-info-other-window (cdr info-section))
|
2003-07-07 01:46:23 -07:00
|
|
|
(ocaml-visible-modules)
|
|
|
|
(let* ((module-info
|
|
|
|
(or (assoc module (ocaml-module-alist))
|
|
|
|
(and (file-exists-p
|
|
|
|
(concat (ocaml-uncapitalize module) ".mli"))
|
2010-01-22 04:48:24 -08:00
|
|
|
(ocaml-get-or-make-module module))))
|
2003-07-07 01:46:23 -07:00
|
|
|
(location (cdr (cadr module-info))))
|
|
|
|
(cond
|
|
|
|
(location
|
2003-11-28 12:14:15 -08:00
|
|
|
(let ((file (concat location (ocaml-uncapitalize module) ".mli")))
|
|
|
|
(if (window-live-p same-window)
|
|
|
|
(progn (select-window same-window)
|
|
|
|
(view-mode-exit view-return-to-alist view-exit-action))
|
|
|
|
;; (view-buffer (find-file-noselect file) 'view))
|
|
|
|
)
|
|
|
|
(view-file-other-window file)
|
|
|
|
(bury-buffer (current-buffer))))
|
2003-07-07 01:46:23 -07:00
|
|
|
(info-section (error "Aborted"))
|
|
|
|
(t (error "No help for module %s" module))))
|
|
|
|
)
|
2002-11-05 23:59:25 -08:00
|
|
|
(if (stringp entry)
|
2002-12-27 10:24:33 -08:00
|
|
|
(let ((here (point))
|
|
|
|
(case-fold-search nil))
|
2002-11-05 23:59:25 -08:00
|
|
|
(goto-char (point-min))
|
2002-12-27 10:24:33 -08:00
|
|
|
(if (or (re-search-forward
|
2003-11-28 10:24:02 -08:00
|
|
|
(concat "\\(val\\|exception\\|type\\|external\\|[|{;]\\) +"
|
2002-12-27 10:24:33 -08:00
|
|
|
(regexp-quote entry))
|
|
|
|
(point-max) t)
|
2003-07-07 01:46:23 -07:00
|
|
|
(re-search-forward
|
|
|
|
(concat "type [^{]*{[^}]*" (regexp-quote entry) " :")
|
|
|
|
(point-max) t)
|
2002-12-27 10:24:33 -08:00
|
|
|
(progn
|
|
|
|
(if (window-live-p window) (select-window window))
|
2003-11-28 10:24:02 -08:00
|
|
|
(error "Entry %s not found in module %s"
|
2002-12-27 10:24:33 -08:00
|
|
|
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)))))
|
2003-07-07 01:46:23 -07:00
|
|
|
(ocaml-link-activate (cdr info-section))
|
2002-11-05 23:59:25 -08:00
|
|
|
(if (window-live-p window) (select-window window))
|
|
|
|
))
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2001-12-03 00:59:32 -08:00
|
|
|
(defun caml-help (arg)
|
2010-01-22 04:48:24 -08:00
|
|
|
"Find documentation for OCaml qualified identifiers.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2003-07-07 01:46:23 -07:00
|
|
|
It attemps to recognize an qualified identifier of the form
|
|
|
|
``Module . entry'' around point using function `ocaml-qualified-identifier'.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2003-07-07 01:46:23 -07:00
|
|
|
If Module is undetermined it is temptatively guessed from the identifier name
|
2010-01-22 04:48:24 -08:00
|
|
|
and according to visible modules. If this is still unsucessful, the user is
|
|
|
|
then prompted for a Module name.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2003-07-07 01:46:23 -07:00
|
|
|
The documentation for Module is first seach in the info manual if available,
|
2010-01-22 04:48:24 -08:00
|
|
|
then in the ``module.mli'' source file. The entry is then searched in the
|
|
|
|
documentation.
|
2001-12-07 09:01:59 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
Visible modules are computed only once, at the first call.
|
2003-07-07 01:46:23 -07:00
|
|
|
Modules can be made visible explicitly with `ocaml-open-module' and
|
2010-01-22 04:48:24 -08:00
|
|
|
hidden with `ocaml-close-module'.
|
2003-07-07 01:46:23 -07:00
|
|
|
|
|
|
|
Prefix arg 0 forces recompilation of visible modules (and their content)
|
2010-01-22 04:48:24 -08:00
|
|
|
from the file content.
|
2003-07-07 01:46:23 -07:00
|
|
|
|
|
|
|
Prefix arg 4 prompts for Module and identifier instead of guessing values
|
2010-01-22 04:48:24 -08:00
|
|
|
from the possition of point in the current buffer.
|
2001-12-07 09:01:59 -08:00
|
|
|
"
|
2001-11-27 03:05:33 -08:00
|
|
|
(interactive "p")
|
2002-11-05 23:59:25 -08:00
|
|
|
(let ((module) (entry) (module-entry))
|
2001-11-27 03:05:33 -08:00
|
|
|
(cond
|
2001-12-07 09:01:59 -08:00
|
|
|
((= arg 4)
|
2001-12-03 00:59:32 -08:00
|
|
|
(or (and
|
|
|
|
(setq module
|
2002-11-05 23:59:25 -08:00
|
|
|
(completing-read "Module: " (ocaml-module-alist)
|
2002-12-27 10:24:33 -08:00
|
|
|
nil t "" (cons 'hist 0)))
|
|
|
|
(not (string-equal module "")))
|
2002-11-05 23:59:25 -08:00
|
|
|
(error "Quit"))
|
|
|
|
(let ((symbols
|
|
|
|
(mapcar 'list
|
|
|
|
(ocaml-module-symbols
|
|
|
|
(assoc module (ocaml-module-alist))))))
|
|
|
|
(setq entry (completing-read "Value: " symbols nil t)))
|
|
|
|
(if (string-equal entry "") (setq entry nil))
|
|
|
|
)
|
2001-11-27 03:05:33 -08:00
|
|
|
(t
|
|
|
|
(if (= arg 0) (setq ocaml-visible-modules 'lazy))
|
2002-11-05 23:59:25 -08:00
|
|
|
(setq module-entry (ocaml-qualified-identifier))
|
|
|
|
(setq entry (ocaml-buffer-substring (cdr module-entry)))
|
|
|
|
(setq module
|
|
|
|
(or (ocaml-buffer-substring (car module-entry))
|
|
|
|
(let ((modules
|
|
|
|
(or (ocaml-find-module entry (ocaml-visible-modules))
|
|
|
|
(ocaml-find-module entry)))
|
2002-12-27 10:24:33 -08:00
|
|
|
(hist) (default))
|
2002-11-05 23:59:25 -08:00
|
|
|
(cond
|
|
|
|
((null modules)
|
|
|
|
(error "No module found for entry %s" entry))
|
|
|
|
((equal (length modules) 1)
|
|
|
|
(caar modules))
|
|
|
|
(t
|
|
|
|
(setq hist (mapcar 'car modules))
|
2002-12-27 10:24:33 -08:00
|
|
|
(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))
|
2002-11-05 23:59:25 -08:00
|
|
|
))))
|
|
|
|
))
|
2001-11-27 03:05:33 -08:00
|
|
|
(message "Help for %s%s%s" module (if entry "." "") (or entry ""))
|
|
|
|
(ocaml-goto-help module entry)
|
|
|
|
))
|
|
|
|
|
2003-07-07 01:46:23 -07:00
|
|
|
;; auto-links
|
|
|
|
|
|
|
|
(defconst ocaml-link-regexp
|
|
|
|
"\\(type\\|and\\) \\('[a-z] +\\|(\\('[a-z], *\\)*'[a-z])\\|\\) *\\([a-zA-Z0-9_]*\\)\\( *$\\| =\\)")
|
|
|
|
(defconst ocaml-longident-regexp
|
|
|
|
"\\([A-Z][a-zA-Z_0]*\\)[.]\\([a-zA-Z][A-Za-z0-9_]*\\)")
|
|
|
|
|
|
|
|
(defvar ocaml-links nil
|
|
|
|
"Local links in the current of last info node or interface file.
|
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
The car of the list is a key that indentifies the module to prevent
|
2003-07-07 01:46:23 -07:00
|
|
|
recompilation when next help command is relative to the same module.
|
|
|
|
The cdr is a list of elments, each of which is an string and a pair of
|
|
|
|
buffer positions."
|
|
|
|
)
|
|
|
|
(make-variable-buffer-local 'ocaml-links)
|
|
|
|
|
|
|
|
(defun ocaml-info-links (section)
|
2010-01-22 04:48:24 -08:00
|
|
|
(cdr
|
2003-11-28 10:24:02 -08:00
|
|
|
(if (and ocaml-links section (equal (car ocaml-links) section))
|
|
|
|
ocaml-links
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let ((regexp (concat (if (equal major-mode 'Info-mode) "^ - " "^")
|
|
|
|
ocaml-link-regexp))
|
|
|
|
(all))
|
|
|
|
(while (re-search-forward regexp (point-max) t)
|
|
|
|
(setq all
|
|
|
|
(cons (cons (match-string 4)
|
|
|
|
(cons (match-beginning 4)
|
|
|
|
(match-end 4)))
|
|
|
|
all)))
|
|
|
|
(setq ocaml-links (cons section all))
|
|
|
|
)))))
|
2003-07-07 01:46:23 -07:00
|
|
|
|
|
|
|
(defvar ocaml-link-map (make-sparse-keymap))
|
|
|
|
(define-key ocaml-link-map [mouse-2] 'ocaml-link-goto)
|
|
|
|
|
|
|
|
(defun ocaml-link-goto (click)
|
|
|
|
(interactive "e")
|
2003-07-28 23:54:28 -07:00
|
|
|
(let* ((pos (caml-event-point-start click))
|
2003-11-28 12:14:15 -08:00
|
|
|
(win (caml-event-window click))
|
|
|
|
(buf (window-buffer win))
|
2003-07-07 01:46:23 -07:00
|
|
|
(window (selected-window))
|
|
|
|
(link))
|
|
|
|
(setq link
|
|
|
|
(with-current-buffer buf
|
2003-11-28 12:14:15 -08:00
|
|
|
(buffer-substring
|
|
|
|
(previous-single-property-change (+ pos 1) 'local-map
|
|
|
|
buf (- pos 100))
|
|
|
|
(next-single-property-change pos 'local-map
|
|
|
|
buf (+ pos 100)))))
|
2003-07-07 01:46:23 -07:00
|
|
|
(if (string-match (concat "^" ocaml-longident-regexp "$") link)
|
2003-11-28 12:14:15 -08:00
|
|
|
(ocaml-goto-help (match-string 1 link) (match-string 2 link) win)
|
2003-07-07 01:46:23 -07:00
|
|
|
(if (not (equal (window-buffer window) buf))
|
|
|
|
(switch-to-buffer-other-window buf))
|
|
|
|
(if (setq link (assoc link (cdr ocaml-links)))
|
|
|
|
(progn
|
|
|
|
(goto-char (cadr link))
|
|
|
|
(recenter 1)))
|
|
|
|
(if (window-live-p window) (select-window window))
|
|
|
|
)))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
((and (x-display-color-p)
|
|
|
|
(not (memq 'ocaml-link-face (face-list))))
|
|
|
|
(make-face 'ocaml-link-face)
|
|
|
|
(set-face-foreground 'ocaml-link-face "Purple")))
|
|
|
|
|
|
|
|
|
|
|
|
(defun ocaml-link-activate (section)
|
2003-11-28 10:24:02 -08:00
|
|
|
(let ((links (ocaml-info-links section)))
|
|
|
|
(if links
|
|
|
|
(let ((regexp (concat "[^A-Za-z0-9'_]\\("
|
|
|
|
ocaml-longident-regexp "\\|"
|
|
|
|
(mapconcat 'car links "\\|")
|
|
|
|
"\\)[^A-Za-z0-9'_]"))
|
|
|
|
(case-fold-search nil))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let ((buffer-read-only nil)
|
|
|
|
;; use of dynamic scoping, need not be restored!
|
|
|
|
(modified-p (buffer-modified-p)))
|
|
|
|
(unwind-protect
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward regexp (point-max) t)
|
|
|
|
(put-text-property (match-beginning 1) (match-end 1)
|
|
|
|
'mouse-face 'highlight)
|
2003-07-07 01:46:23 -07:00
|
|
|
(put-text-property (match-beginning 1) (match-end 1)
|
2003-11-28 10:24:02 -08:00
|
|
|
'local-map ocaml-link-map)
|
|
|
|
(if (x-display-color-p)
|
|
|
|
(put-text-property (match-beginning 1) (match-end 1)
|
|
|
|
'face 'ocaml-link-face)))
|
|
|
|
)
|
2010-01-22 04:48:24 -08:00
|
|
|
;; need to restore flag if buffer was unmodified.
|
2003-11-28 10:24:02 -08:00
|
|
|
(unless modified-p (set-buffer-modified-p nil))
|
|
|
|
))
|
|
|
|
))))
|
2003-07-07 01:46:23 -07:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
;; bindings ---now in caml.el
|
|
|
|
|
|
|
|
; (and
|
|
|
|
; (boundp 'caml-mode-map)
|
|
|
|
; (keymapp caml-mode-map)
|
2010-01-22 04:48:24 -08:00
|
|
|
; (progn
|
2003-07-24 01:46:52 -07:00
|
|
|
; (define-key caml-mode-map [?\C-c?i] 'ocaml-add-path)
|
|
|
|
; (define-key caml-mode-map [?\C-c?]] 'ocaml-close-module)
|
|
|
|
; (define-key caml-mode-map [?\C-c?[] 'ocaml-open-module)
|
|
|
|
; (define-key caml-mode-map [?\C-c?\C-h] 'caml-help)
|
|
|
|
; (define-key caml-mode-map [?\C-c?\t] 'caml-complete)
|
|
|
|
; (let ((map (lookup-key caml-mode-map [menu-bar caml])))
|
|
|
|
; (and
|
|
|
|
; (keymapp map)
|
|
|
|
; (progn
|
|
|
|
; (define-key map [separator-help] '("---"))
|
|
|
|
; (define-key map [open] '("Open add path" . ocaml-add-path ))
|
|
|
|
; (define-key map [close]
|
|
|
|
; '("Close module for help" . ocaml-close-module))
|
|
|
|
; (define-key map [open] '("Open module for help" . ocaml-open-module))
|
|
|
|
; (define-key map [help] '("Help for identifier" . caml-help))
|
|
|
|
; (define-key map [complete] '("Complete identifier" . caml-complete))
|
2010-01-22 04:48:24 -08:00
|
|
|
; )
|
2003-07-24 01:46:52 -07:00
|
|
|
; ))))
|
2002-11-07 06:05:53 -08:00
|
|
|
|
2001-11-27 03:05:33 -08:00
|
|
|
|
|
|
|
(provide 'caml-help)
|