emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/caml 118fade: Silence the worse warnings


From: ELPA Syncer
Subject: [nongnu] elpa/caml 118fade: Silence the worse warnings
Date: Fri, 20 Aug 2021 04:57:19 -0400 (EDT)

branch: elpa/caml
commit 118fade8fac4477226f2f2db134397416afb63a2
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Christophe Troestler <Christophe.Troestler@umons.ac.be>

    Silence the worse warnings
    
    Highlights:
    - Add a `Package-Requires:` header.  Set it for Emacs-22 since the
      caml.el code uses \_< and \_> regexps which were added in Emacs-22.
    - Add a `Version:` header so the NonGNU ELPA knows which versions
      this is.  It's set to `4.7.1` which is the last release of this
      package, AFAIK.  Since that's 3 years old, it would be nice to bump
      this version number soonish in order to create a new release.
    - Remove caml-hilit.el since hilit.el was made obsolete by font-lock
      sometimes during the Emacs-19 days.
    - Remove caml-compat.el since it's only used for Emacs < 20 or so.
    - Remove caml-mode-site-file.el since I can't see any reference to
      it anywhere.  An alternative would be to keep its Makefile rule and
      mention it in the README, but in any case it doesn't belong in the Git.
    - Mark files with `lexical-binding`.  The code doesn't actually rely
      on this feature, but it should work both ways now and you get better
      warnings with `lexical-binding` enabled.
    - Use `cl-lib` (explicitly) rather than `cl` (implicitly) in
      `caml-help.el`.
    - Use the "new" interface of sit-for used in XEmacs and Emacs ≥ 22.
    - Use define-derived-mode.
    - Try and define variables directly in their declaration rather
      than separately.
---
 .gitignore             |   3 +
 Makefile               |  14 +--
 caml-compat.el         |  41 -------
 caml-font-old.el       |   4 +-
 caml-font.el           |   4 +-
 caml-help.el           |  54 +++++----
 caml-hilit.el          |  67 -----------
 caml-mode-site-file.el |  90 ---------------
 caml-types.el          |  46 +++++---
 caml.el                | 308 ++++++++++++++++++++++---------------------------
 camldebug.el           | 125 ++++++++++----------
 inf-caml.el            |  59 +++++-----
 12 files changed, 298 insertions(+), 517 deletions(-)

diff --git a/.gitignore b/.gitignore
index e56a06c..bba222e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
+*.elc
+/caml-pkg.el
+/caml-autoloads.el
 *.tgz
 caml-mode.*/
diff --git a/Makefile b/Makefile
index 509bfa4..a8c19b1 100644
--- a/Makefile
+++ b/Makefile
@@ -21,9 +21,9 @@ OPAM_DIR = caml-mode.$(VERSION)
 TARBALL = caml-mode-$(VERSION).tgz
 
 # Files to install
-FILES= caml-font.el caml-hilit.el caml.el camldebug.el \
-       inf-caml.el caml-compat.el caml-help.el caml-types.el \
-       caml-xemacs.el caml-emacs.el caml-mode-site-file.el
+FILES= caml-font.el caml.el camldebug.el      \
+       inf-caml.el caml-help.el caml-types.el \
+       caml-xemacs.el caml-emacs.el
 
 DIST_FILES = $(FILES) Makefile README* COPYING* CHANGES.md ocamltags.in
 
@@ -48,14 +48,6 @@ COMPILECMD=(progn \
              (byte-compile-file "caml-font.el") \
              (byte-compile-file "camldebug.el"))
 
-caml-mode-site-file.el: $(SOURCES)
-       (echo ";;; $@ --- Automatically extracted autoloads.";\
-        echo ";;; Code:";\
-        echo "(add-to-list 'load-path";\
-        echo "             (or (file-name-directory load-file-name) (car 
load-path)))";\
-        echo "") >$@
-       $(EMACS) --batch --eval '(setq generated-autoload-file "'`pwd`'/$@")' 
-f batch-update-autoloads "."
-
 install:
        @if test "$(EMACSDIR)" = ""; then \
          $(EMACS) --batch --eval 't; see PR#5403'; \
diff --git a/caml-compat.el b/caml-compat.el
deleted file mode 100644
index 782d2d4..0000000
--- a/caml-compat.el
+++ /dev/null
@@ -1,41 +0,0 @@
-;**************************************************************************
-;*                                                                        *
-;*                                 OCaml                                  *
-;*                                                                        *
-;*            Xavier Leroy, projet Cristal, INRIA Rocquencourt            *
-;*                                                                        *
-;*   Copyright 1998 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.                                      *
-;*                                                                        *
-;**************************************************************************
-
-;; function definitions for old versions of emacs
-
-;; indent-line-to
-
-(if (not (fboundp 'indent-line-to))
-    (defun indent-line-to (column)
-      "Indent current line to COLUMN.
-
-This function removes or adds spaces and tabs at beginning of line
-only if necessary.  It leaves point at end of indentation."
-      (if (= (current-indentation) column)
-          (back-to-indentation)
-        (beginning-of-line 1)
-        (delete-horizontal-space)
-        (indent-to column))))
-
-;; buffer-substring-no-properties
-
-(cond
- ((fboundp 'buffer-substring-no-properties))
- ((fboundp 'buffer-substring-without-properties)
-  (defalias 'buffer-substring-no-properties
-    'buffer-substring-without-properties))
- (t
-  (defalias 'buffer-substring-no-properties 'buffer-substring)))
-
-(provide 'caml-compat)
diff --git a/caml-font-old.el b/caml-font-old.el
index 949ca32..b9d4637 100644
--- a/caml-font-old.el
+++ b/caml-font-old.el
@@ -1,4 +1,4 @@
-;**************************************************************************
+;****************************************** -*- lexical-binding: t; -*- ***
 ;*                                                                        *
 ;*                                 OCaml                                  *
 ;*                                                                        *
@@ -67,7 +67,7 @@
           "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)"
           "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)"
           "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>"
-          "\\|\|\\|->\\|&\\|#")
+          "\\||\\|->\\|&\\|#")
          'font-lock-reference-face)
    '("\\<raise\\>" . font-lock-comment-face)
 ;labels (and open)
diff --git a/caml-font.el b/caml-font.el
index 3a534ff..71f0eb7 100644
--- a/caml-font.el
+++ b/caml-font.el
@@ -1,4 +1,4 @@
-;**************************************************************************
+;****************************************** -*- lexical-binding: t; -*- ***
 ;*                                                                        *
 ;*                                 OCaml                                  *
 ;*                                                                        *
@@ -349,7 +349,7 @@
 ; It finds the nearest saved state at the left of the changed text,
 ; calls caml-font-annotate to set the 'caml-font-state and 'syntax-table
 ; properties, then returns the range that was parsed by caml-font-annotate.
-(defun caml-font-extend-after-change (beg end &optional old-len)
+(defun caml-font-extend-after-change (beg end &optional _old-len)
   (save-excursion
     (save-match-data
       (let ((caml-font-modified (buffer-modified-p))
diff --git a/caml-help.el b/caml-help.el
index 9e3a221..90b0cd5 100644
--- a/caml-help.el
+++ b/caml-help.el
@@ -1,4 +1,4 @@
-;;; caml-help.el --- Contextual completion and help to caml-mode
+;;; caml-help.el --- Contextual completion and help to caml-mode  -*- 
lexical-binding: t; -*-
 ;**************************************************************************
 ;*                                                                        *
 ;*                                 OCaml                                  *
@@ -53,6 +53,11 @@
 
 ;; variables to be customized
 
+(defgroup caml-help nil
+  "Customizations for `caml-help'.")
+
+(require 'cl-lib)
+
 (defvar ocaml-lib-path 'lazy
   "Path list for ocaml lib sources (mli files).
 
@@ -132,15 +137,15 @@
       (setq files (cdr files)))
     modules))
 
-(defun ocaml-add-path (dir &optional path)
+(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))
+             (or (cl-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))))
@@ -157,11 +162,11 @@
     )
   ocaml-module-alist)
 
-(defun ocaml-get-or-make-module (module &optional tag)
+(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))
+      (push info ocaml-module-alist)
       )
     info))
 
@@ -247,7 +252,7 @@ When call interactively, make completion over known 
modules."
         (setq ocaml-visible-modules
               (cons (ocaml-get-or-make-module arg) (ocaml-visible-modules)))
         ))
-  (message "%S" (mapcar 'car (ocaml-visible-modules))))
+  (message "%S" (mapcar #'car (ocaml-visible-modules))))
 
 (defun ocaml-close-module (arg)
   "*Close module of name ARG when ARG is a string.
@@ -265,10 +270,10 @@ Otherwise if ARG is true, close all modules and reset to 
default."
                modules))
         (if (equal arg "") (setq arg (caar modules))))
       (setq ocaml-visible-modules
-            (remove-if (lambda (m) (equal (car m) arg))
-                       ocaml-visible-modules))
+            (cl-remove-if (lambda (m) (equal (car m) arg))
+                          ocaml-visible-modules))
       ))
-  (message "%S" (mapcar 'car (ocaml-visible-modules))))
+  (message "%S" (mapcar #'car (ocaml-visible-modules))))
 
 
 ;; Look for identifiers around point
@@ -318,9 +323,9 @@ with an optional non-nil argument."
                 (or (assoc module (ocaml-module-alist))
                     (error "Unknown module %s" module))))
           (ocaml-visible-modules))))
-    (message "Completion from %s" (mapconcat 'car list " "))
+    (message "Completion from %s" (mapconcat #'car list " "))
     (if (null pattern)
-        (apply 'append (mapcar 'ocaml-module-symbols list))
+        (apply #'append (mapcar #'ocaml-module-symbols list))
       (let ((pat (concat "^" (regexp-quote pattern))) (res))
         (mapc
          (lambda (l)
@@ -332,7 +337,7 @@ with an optional non-nil argument."
         res)
       )))
 
-(defun caml-complete (arg)
+(defun caml-complete (&optional _arg)
   "Does completion for OCaml identifiers qualified.
 
 It attemps to recognize a qualified identifier Module . entry
@@ -343,9 +348,9 @@ If Module is defined, it does completion for identifier in 
Module.
 If Module is undefined, it does completion in visible modules.
 Then, if completion fails, it does completion among  all modules
 where identifier is defined."
-  (interactive "p")
-  (let* ((module-entry (ocaml-qualified-identifier)) (entry)
-         (module)
+  (interactive "")
+  (let* ((module-entry (ocaml-qualified-identifier))
+         (module) ;; (entry)
          (beg) (end) (pattern))
     (if (car module-entry)
         (progn
@@ -361,7 +366,8 @@ where identifier is defined."
                      (insert module) t)
                    (setq module-entry (ocaml-qualified-identifier))
                    (car module-entry)
-                   (progn (setq entry (cdr module-entry)) t))
+                   (progn ;; (setq entry (cdr module-entry))
+                          t))
               (error "Unknown module %s" module))))
     (if (consp (cdr module-entry))
         (progn
@@ -380,13 +386,13 @@ where identifier is defined."
       (setq pattern (buffer-substring beg end))
       (let* ((all-completions (ocaml-completion pattern module))
              (completion
-              (try-completion pattern (mapcar 'list all-completions))))
+              (try-completion pattern all-completions)))
         (cond ((eq completion t))
 
               ((null completion)
                (let*
                    ((modules (ocaml-find-module pattern))
-                    (visible (intersection modules (ocaml-visible-modules)))
+                    (visible (cl-intersection modules (ocaml-visible-modules)))
                     (hist)
                     (module
                      (cond
@@ -397,7 +403,7 @@ where identifier is defined."
                       ((equal (length visible) 1)
                        (caar visible))
                       (t
-                       (setq hist (mapcar 'car modules))
+                       (setq hist (mapcar #'car modules))
                        (completing-read "Module: " modules nil t
                                         "" (cons hist 0)))
                       )))
@@ -444,7 +450,7 @@ Additional suffix .gz may be added if info files are 
compressed.")
     (if (or (null files)
             (not (stringp files))
             (string-match files "^ *$"))
-        (message "No info file found: %s." (mapconcat 'identity files " "))
+        (message "No info file found: %s." (mapconcat #'identity files " "))
       (message "Scanning info files %s." files)
       (save-window-excursion
         (set-buffer (get-buffer-create "*caml-help*"))
@@ -679,7 +685,7 @@ from the position of point in the current buffer."
            (not (string-equal module "")))
           (error "Quit"))
       (let ((symbols
-             (mapcar 'list
+             (mapcar #'list
                      (ocaml-module-symbols
                       (assoc module (ocaml-module-alist))))))
         (setq entry
@@ -702,7 +708,7 @@ from the position of point in the current buffer."
                    ((equal (length modules) 1)
                     (caar modules))
                    (t
-                    (setq hist (mapcar 'car modules))
+                    (setq hist (mapcar #'car modules))
                     (setq default (car hist))
                     (setq module
                           (completing-read
@@ -800,7 +806,7 @@ buffer positions."
     (if links
         (let ((regexp (concat "[^A-Za-z0-9'_]\\("
                               ocaml-longident-regexp "\\|"
-                              (mapconcat 'car links "\\|")
+                              (mapconcat #'car links "\\|")
                               "\\)[^A-Za-z0-9'_]"))
               (case-fold-search nil))
           (save-excursion
diff --git a/caml-hilit.el b/caml-hilit.el
deleted file mode 100644
index 03d6465..0000000
--- a/caml-hilit.el
+++ /dev/null
@@ -1,67 +0,0 @@
-;**************************************************************************
-;*                                                                        *
-;*                                 OCaml                                  *
-;*                                                                        *
-;*                 Jacques Garrigue and Ian T Zimmerman                   *
-;*                                                                        *
-;*   Copyright 1997 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.                                      *
-;*                                                                        *
-;**************************************************************************
-
-; Highlighting patterns for hilit19 under caml-mode
-
-; defined also in caml.el
-(defvar caml-quote-char "'"
-  "*Quote for character constants. \"'\" for OCaml, \"`\" for Caml-Light.")
-
-(defconst caml-mode-patterns
-  (list
-;comments
-   '("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)"
-     2 comment)
-;string
-   (list 'hilit-string-find (string-to-char caml-quote-char) 'string)
-   (list (concat caml-quote-char "\\(\\\\\\([ntbr" caml-quote-char "\\]\\|"
-                 "[0-9][0-9][0-9]\\)\\|.\\)" caml-quote-char)
-         nil
-         'string)
-;labels
-   '("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" 1 brown)
-   '("[~?][ (]*[a-z][a-zA-Z0-9_']*" nil brown)
-;modules
-   '("\\<\\(assert\\|open\\|include\\)\\>" nil brown)
-   '("`?\\<[A-Z][A-Za-z0-9_\']*\\>" nil MidnightBlue)
-;definition
-   (list (concat
-          "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)"
-          "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?"
-          "\\|in\\(herit\\)?\\|let\\|m\\(ethod\\|utable\\|odule\\)"
-          "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type"
-          "\\|v\\(al\\|irtual\\)\\)\\>")
-         nil 'ForestGreen)
-;blocking
-   '("\\<\\(object\\|struct\\|sig\\|begin\\|end\\)\\>" 2 include)
-;control
-   (list (concat
-          "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)"
-          "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)"
-          "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>"
-          "\\|\|\\|->\\|&\\|#")
-         nil 'keyword)
-   '(";" nil struct))
-  "Hilit19 patterns used for OCaml mode")
-
-(hilit-set-mode-patterns 'caml-mode caml-mode-patterns)
-(hilit-set-mode-patterns
- 'inferior-caml-mode
- (append
-  (list
-;inferior
-   '("^[#-]"    nil     firebrick))
-  caml-mode-patterns))
-
-(provide 'caml-hilit)
diff --git a/caml-mode-site-file.el b/caml-mode-site-file.el
deleted file mode 100644
index 0d8177a..0000000
--- a/caml-mode-site-file.el
+++ /dev/null
@@ -1,90 +0,0 @@
-;;; caml-mode-site-file.el --- Automatically extracted autoloads.
-;;; Code:
-(add-to-list 'load-path
-             (or (file-name-directory load-file-name) (car load-path)))
-
-;;;### (autoloads nil "caml" "caml.el" (0 0 0 0))
-;;; Generated autoloads from caml.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml" '("caml-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-emacs" "caml-emacs.el" (0 0 0 0))
-;;; Generated autoloads from caml-emacs.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-emacs" '("caml-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-font" "caml-font.el" (0 0 0 0))
-;;; Generated autoloads from caml-font.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-font" '("inferior-caml-" "caml-font-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-font-old" "caml-font-old.el" (0 0 0 0))
-;;; Generated autoloads from caml-font-old.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-font-old" '("inferior-caml-" "caml-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-help" "caml-help.el" (0 0 0 0))
-;;; Generated autoloads from caml-help.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-help" '("ocaml-" "caml-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-hilit" "caml-hilit.el" (0 0 0 0))
-;;; Generated autoloads from caml-hilit.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-hilit" '("caml-")))
-
-;;;***
-
-;;;### (autoloads nil "caml-types" "caml-types.el" (0 0 0 0))
-;;; Generated autoloads from caml-types.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-types" '("caml-" "next-annotation")))
-
-;;;***
-
-;;;### (autoloads nil "caml-xemacs" "caml-xemacs.el" (0 0 0 0))
-;;; Generated autoloads from caml-xemacs.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"caml-xemacs" '("caml-")))
-
-;;;***
-
-;;;### (autoloads nil "camldebug" "camldebug.el" (0 0 0 0))
-;;; Generated autoloads from camldebug.el
-
-(defvar camldebug-command-name "ocamldebug" "\
-*Pathname for executing camldebug.")
-
-(autoload 'camldebug "camldebug" "\
-Run camldebug on program FILE in buffer *camldebug-FILE*.
-The directory containing FILE becomes the initial working directory
-and source-file directory for camldebug.  If you wish to change this, use
-the camldebug commands `cd DIR' and `directory'.
-
-\(fn PATH)" t nil)
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"camldebug" '("current-camldebug-buffer" "camldebug-" "def-camldebug")))
-
-;;;***
-
-;;;### (autoloads nil "inf-caml" "inf-caml.el" (0 0 0 0))
-;;; Generated autoloads from inf-caml.el
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes 
"inf-caml" '("caml-" "inferior-caml-" "run-caml")))
-
-;;;***
-
-;;;### (autoloads nil nil ("caml-compat.el") (0 0 0 0))
-
-;;;***
-
diff --git a/caml-types.el b/caml-types.el
index e923685..81800bd 100644
--- a/caml-types.el
+++ b/caml-types.el
@@ -1,4 +1,4 @@
-;**************************************************************************
+;**************************************************************************  
-*- lexical-binding: t; -*-
 ;*                                                                        *
 ;*                                 OCaml                                  *
 ;*                                                                        *
@@ -17,10 +17,12 @@
 ;; XEmacs compatibility
 
 (eval-and-compile
-  (if (and (boundp 'running-xemacs) running-xemacs)
+  (if (featurep 'xemacs)
       (require 'caml-xemacs)
     (require 'caml-emacs)))
 
+(defvar caml-types-buffer)              ;Forward declaration.
+
 (defun caml-types-feedback (info format)
   "Displays INFO using the given FORMAT."
   (message (format format info))
@@ -85,6 +87,9 @@ type call ident")
   (setq caml-types-location-re
         (concat "^" caml-types-position-re " " caml-types-position-re)))
 
+(defgroup caml-types nil
+  "Customization for `caml-types'.")
+
 (defface caml-types-expr-face
   '((((class color) (background light)) :background "#88FF44")
     (((class color) (background  dark)) :background "dark green"))
@@ -132,6 +137,8 @@ type call ident")
 (defvar caml-types-buffer nil
   "Buffer for displaying caml types.")
 
+(defvar target-file) ;; FIXME: Get rid of this dynbound variable!
+
 (defun caml-types-show-type (arg)
   "Show the type of expression or pattern at point.
 
@@ -394,7 +401,7 @@ corresponding .annot file."
   (symbol-name (intern elem table)))
 
 
-(defun next-annotation ()
+(defun caml-types--next-annotation ()
   (forward-char 1)
   (if (re-search-forward "^[a-z\"]" () t)
       (forward-char -1)
@@ -408,8 +415,9 @@ corresponding .annot file."
 ;   (kind . info) where kind = "type" "call" etc.
 ;                 and info = the contents of the annotation
 
-(defun caml-types-build-tree (target-file)
-  (let ((stack ())
+(defun caml-types-build-tree (t-file)
+  (let ((target-file t-file)
+        (stack ())
         (accu ())
         (table (caml-types-make-hash-table))
         (annotation ()))
@@ -424,7 +432,7 @@ corresponding .annot file."
             (r-cnum (caml-string-to-int (match-string 10))))
         (unless (caml-types-not-in-file l-file r-file target-file)
           (setq annotation ())
-          (while (next-annotation)
+          (while (caml-types--next-annotation)
             (cond ((looking-at "^\\([a-z]+\\)(\n  \\(\\(.*\n  \\)*.*\\)\n)")
                    (let ((kind (caml-types-hcons (match-string 1) table))
                          (info (caml-types-hcons (match-string 2) table)))
@@ -447,11 +455,11 @@ corresponding .annot file."
             (car stack)
           (caml-types-make-node left-pos right-pos () (nreverse stack)))))))
 
-(defun caml-types-not-in-file (l-file r-file target-file)
-  (or (and (not (string= l-file target-file))
-           (not (string= l-file "")))
-      (and (not (string= r-file target-file))
-           (not (string= r-file "")))))
+(defun caml-types-not-in-file (l-file r-file t-file)
+  (not (and (or (string= l-file t-file)
+                (string= l-file ""))
+            (or (string= r-file t-file)
+                (string= r-file "")))))
 
 (defun caml-types-make-node (left-pos right-pos annotation children)
   (let ((result (make-vector (+ 3 (length children)) ()))
@@ -564,11 +572,13 @@ corresponding .annot file."
                     (> (- cnum1 bol1) (- cnum2 bol2))))))))
 
 (defun caml-types-get-pos (buf pos)
-  (save-excursion
-    (set-buffer buf)
-    (goto-line (elt pos 1))
-    (forward-char (- (elt pos 3) (elt pos 2)))
-    (point)))
+  (with-current-buffer buf
+    (save-restriction
+      (widen)
+      (goto-char (point-min))
+      (forward-line (1- (elt pos 1)))
+      (forward-char (- (elt pos 3) (elt pos 2)))
+      (point))))
 
 ; find-file-read-only-noselect seems to be missing from emacs...
 (defun caml-types-find-file (name)
@@ -586,7 +596,7 @@ corresponding .annot file."
     (error (format "Can't read the annotation file `%s'" name))))
   buf))
 
-(defun caml-types-mouse-ignore (event)
+(defun caml-types-mouse-ignore (_event)
   (interactive "e")
   nil)
 
@@ -612,7 +622,7 @@ The function uses two overlays.
          (target-file (file-name-nondirectory (buffer-file-name)))
          (target-line) (target-bol)
          target-pos
-         Left Right limits cnum node mes type
+         limits cnum node mes type
          region
          (window (caml-event-window event))
          target-tree
diff --git a/caml.el b/caml.el
index 81c25c4..a24f348 100644
--- a/caml.el
+++ b/caml.el
@@ -1,4 +1,4 @@
-;;; caml.el --- OCaml code editing commands for Emacs
+;;; caml.el --- OCaml code editing commands for Emacs  -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 1997-2017 Institut National de Recherche en Informatique et 
en Automatique.
 
@@ -6,6 +6,8 @@
 ;;         Ian T Zimmerman <itz@rahul.net>
 ;; Maintainer: Damien Doligez <damien.doligez@inria.fr>
 ;; Created: July 1993
+;; Package-Requires: ((emacs "22") (cl-lib "0.5"))
+;; Version: 4.7.1
 ;; Keywords: OCaml
 ;; Homepage: https://github.com/ocaml/ocaml/
 
@@ -286,109 +288,104 @@ you are one.  You should probably have this on, though, 
if you also
 have `caml-electric-indent' on, which see.")
 
 ;;code
-(if (or (not (fboundp 'indent-line-to))
-        (not (fboundp 'buffer-substring-no-properties)))
-    (require 'caml-compat))
 
 (defvar caml-shell-active nil
   "Non nil when a subshell is running.")
 
-(defvar caml-mode-map nil
-  "Keymap used in Caml mode.")
-(if caml-mode-map
-    ()
-  (setq caml-mode-map (make-sparse-keymap))
-  (define-key caml-mode-map "|" 'caml-electric-pipe)
-  (define-key caml-mode-map "}" 'caml-electric-pipe)
-  (define-key caml-mode-map "]" 'caml-electric-rb)
-  (define-key caml-mode-map "\t" 'caml-indent-command)
-  (define-key caml-mode-map [backtab] 'caml-unindent-command)
-
-;itz 04-21-96 instead of defining a new function, use defadvice
-;that way we get out effect even when we do \C-x` in compilation buffer
-;  (define-key caml-mode-map "\C-x`" 'caml-next-error)
-
-  (if (featurep 'xemacs)
-      (define-key caml-mode-map 'backspace 'backward-delete-char-untabify)
-    (define-key caml-mode-map "\177" 'backward-delete-char-untabify))
-
-  ;; caml-types
-  (define-key caml-mode-map [?\C-c?\C-t] 'caml-types-show-type)  ; "type"
-  (define-key caml-mode-map [?\C-c?\C-f] 'caml-types-show-call)  ; "function"
-  (define-key caml-mode-map [?\C-c?\C-l] 'caml-types-show-ident) ; "let"
-  ;; must be a mouse-down event. Can be any button and any prefix
-  (define-key caml-mode-map [?\C-c down-mouse-1] 'caml-types-explore)
-  ;; caml-help
-  (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)
-  ;; others
-  (define-key caml-mode-map "\C-cb" 'caml-insert-begin-form)
-  (define-key caml-mode-map "\C-cf" 'caml-insert-for-form)
-  (define-key caml-mode-map "\C-ci" 'caml-insert-if-form)
-  (define-key caml-mode-map "\C-cl" 'caml-insert-let-form)
-  (define-key caml-mode-map "\C-cm" 'caml-insert-match-form)
-  (define-key caml-mode-map "\C-ct" 'caml-insert-try-form)
-  (define-key caml-mode-map "\C-cw" 'caml-insert-while-form)
-  (define-key caml-mode-map "\C-c`" 'caml-goto-phrase-error)
-  (define-key caml-mode-map "\C-c\C-a" 'caml-find-alternate-file)
-  (define-key caml-mode-map "\C-c\C-c" 'compile)
-  (define-key caml-mode-map "\C-c\C-e" 'caml-eval-phrase)
-  (define-key caml-mode-map "\C-c\C-[" 'caml-backward-to-less-indent)
-  (define-key caml-mode-map "\C-c\C-]" 'caml-forward-to-less-indent)
-  (define-key caml-mode-map "\C-c\C-q" 'caml-indent-phrase)
-  (define-key caml-mode-map "\C-c\C-r" 'caml-eval-region)
-  (define-key caml-mode-map "\C-c\C-s" 'caml-show-subshell)
-  (define-key caml-mode-map "\M-\C-h" 'caml-mark-phrase)
-  (define-key caml-mode-map "\M-\C-q" 'caml-indent-phrase)
-  (define-key caml-mode-map "\M-\C-x" 'caml-eval-phrase)
-
-  (if (featurep 'xemacs) nil
-    (let ((map (make-sparse-keymap "Caml"))
-          (forms (make-sparse-keymap "Forms")))
-      (define-key caml-mode-map "\C-c\C-d" 'caml-show-imenu)
-      (define-key caml-mode-map [menu-bar] (make-sparse-keymap))
-      (define-key caml-mode-map [menu-bar caml] (cons "Caml" map))
-      ;; caml-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))
-      (define-key map [separator-help] '("---"))
-
-      ;; caml-types
-      (define-key map [show-type]
+(defvar caml-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "|" 'caml-electric-pipe)
+    (define-key map "}" 'caml-electric-pipe)
+    (define-key map "]" 'caml-electric-rb)
+    (define-key map "\t" 'caml-indent-command)
+    (define-key map [backtab] 'caml-unindent-command)
+
+    ;;itz 04-21-96 instead of defining a new function, use defadvice
+    ;;that way we get out effect even when we do \C-x` in compilation buffer
+    ;;  (define-key map "\C-x`" 'caml-next-error)
+
+    (define-key map (if (featurep 'xemacs) 'backspace "\177")
+      'backward-delete-char-untabify)
+
+    ;; caml-types
+    (define-key map [?\C-c?\C-t] 'caml-types-show-type)  ; "type"
+    (define-key map [?\C-c?\C-f] 'caml-types-show-call)  ; "function"
+    (define-key map [?\C-c?\C-l] 'caml-types-show-ident) ; "let"
+    ;; must be a mouse-down event. Can be any button and any prefix
+    (define-key map [?\C-c down-mouse-1] 'caml-types-explore)
+    ;; caml-help
+    (define-key map [?\C-c?i] 'ocaml-add-path)
+    (define-key map [?\C-c?\]] 'ocaml-close-module)
+    (define-key map [?\C-c?\[] 'ocaml-open-module)
+    (define-key map [?\C-c?\C-h] 'caml-help)
+    (define-key map [?\C-c?\t] 'caml-complete)
+    ;; others
+    (define-key map "\C-cb" 'caml-insert-begin-form)
+    (define-key map "\C-cf" 'caml-insert-for-form)
+    (define-key map "\C-ci" 'caml-insert-if-form)
+    (define-key map "\C-cl" 'caml-insert-let-form)
+    (define-key map "\C-cm" 'caml-insert-match-form)
+    (define-key map "\C-ct" 'caml-insert-try-form)
+    (define-key map "\C-cw" 'caml-insert-while-form)
+    (define-key map "\C-c`" 'caml-goto-phrase-error)
+    (define-key map "\C-c\C-a" 'caml-find-alternate-file)
+    (define-key map "\C-c\C-c" 'compile)
+    (define-key map "\C-c\C-e" 'caml-eval-phrase)
+    (define-key map "\C-c\C-[" 'caml-backward-to-less-indent)
+    (define-key map "\C-c\C-]" 'caml-forward-to-less-indent)
+    (define-key map "\C-c\C-q" 'caml-indent-phrase)
+    (define-key map "\C-c\C-r" 'caml-eval-region)
+    (define-key map "\C-c\C-s" 'caml-show-subshell)
+    (define-key map "\M-\C-h" 'caml-mark-phrase)
+    (define-key map "\M-\C-q" 'caml-indent-phrase)
+    (define-key map "\M-\C-x" 'caml-eval-phrase)
+
+    (if (featurep 'xemacs) nil
+      (let ((menu (make-sparse-keymap "Caml"))
+            (forms (make-sparse-keymap "Forms")))
+        (define-key map "\C-c\C-d" 'caml-show-imenu)
+        (define-key map [menu-bar] (make-sparse-keymap))
+        (define-key map [menu-bar caml] (cons "Caml" menu))
+        ;; caml-help
+
+        (define-key menu [open] '("Open add path" . ocaml-add-path ))
+        (define-key menu [close]
+          '("Close module for help" . ocaml-close-module))
+        (define-key menu [open] '("Open module for help" . ocaml-open-module))
+        (define-key menu [help] '("Help for identifier" . caml-help))
+        (define-key menu [complete] '("Complete identifier" . caml-complete))
+        (define-key menu [separator-help] '("---"))
+
+        ;; caml-types
+        (define-key menu [show-type]
           '("Show type at point" . caml-types-show-type ))
-      (define-key map [separator-types] '("---"))
-
-      ;; others
-      (define-key map [camldebug] '("Call debugger..." . camldebug))
-      (define-key map [run-caml] '("Start subshell..." . run-caml))
-      (define-key map [compile] '("Compile..." . compile))
-      (define-key map [switch-view]
-        '("Switch view" . caml-find-alternate-file))
-      (define-key map [separator-format] '("--"))
-      (define-key map [forms] (cons "Forms" forms))
-      (define-key map [show-imenu] '("Show index" . caml-show-imenu))
-      (put 'caml-show-imenu 'menu-enable '(not caml-imenu-shown))
-      (define-key map [show-subshell] '("Show subshell" . caml-show-subshell))
-      (put 'caml-show-subshell 'menu-enable 'caml-shell-active)
-      (define-key map [eval-phrase] '("Eval phrase" . caml-eval-phrase))
-      (put 'caml-eval-phrase 'menu-enable 'caml-shell-active)
-      (define-key map [indent-phrase] '("Indent phrase" . caml-indent-phrase))
-      (define-key forms [while]
-        '("while .. do .. done" . caml-insert-while-form))
-      (define-key forms [try] '("try .. with .." . caml-insert-try-form))
-      (define-key forms [match] '("match .. with .." . caml-insert-match-form))
-      (define-key forms [let] '("let .. in .." . caml-insert-let-form))
-      (define-key forms [if] '("if .. then .. else .." . caml-insert-if-form))
-      (define-key forms [begin] '("for .. do .. done" . caml-insert-for-form))
-      (define-key forms [begin] '("begin .. end" . caml-insert-begin-form)))))
+        (define-key menu [separator-types] '("---"))
+
+        ;; others
+        (define-key menu [camldebug] '("Call debugger..." . camldebug))
+        (define-key menu [run-caml] '("Start subshell..." . run-caml))
+        (define-key menu [compile] '("Compile..." . compile))
+        (define-key menu [switch-view]
+          '("Switch view" . caml-find-alternate-file))
+        (define-key menu [separator-format] '("--"))
+        (define-key menu [forms] (cons "Forms" forms))
+        (define-key menu [show-imenu] '("Show index" . caml-show-imenu))
+        (put 'caml-show-imenu 'menu-enable '(not caml-imenu-shown))
+        (define-key menu [show-subshell] '("Show subshell" . 
caml-show-subshell))
+        (put 'caml-show-subshell 'menu-enable 'caml-shell-active)
+        (define-key menu [eval-phrase] '("Eval phrase" . caml-eval-phrase))
+        (put 'caml-eval-phrase 'menu-enable 'caml-shell-active)
+        (define-key menu [indent-phrase] '("Indent phrase" . 
caml-indent-phrase))
+        (define-key forms [while]
+          '("while .. do .. done" . caml-insert-while-form))
+        (define-key forms [try] '("try .. with .." . caml-insert-try-form))
+        (define-key forms [match] '("match .. with .." . 
caml-insert-match-form))
+        (define-key forms [let] '("let .. in .." . caml-insert-let-form))
+        (define-key forms [if] '("if .. then .. else .." . 
caml-insert-if-form))
+        (define-key forms [begin] '("for .. do .. done" . 
caml-insert-for-form))
+        (define-key forms [begin] '("begin .. end" . caml-insert-begin-form))))
+    map)
+  "Keymap used in Caml mode.")
 
 (defvar caml-mode-xemacs-menu
   (if (featurep 'xemacs)
@@ -420,31 +417,30 @@ have `caml-electric-indent' on, which see.")
         ))
   "Menu to add to the menubar when running Xemacs.")
 
-(defvar caml-mode-syntax-table nil
-  "Syntax table in use in Caml mode buffers.")
-(if caml-mode-syntax-table
-    ()
-  (let ((n (if (featurep 'xemacs) "" "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
+(defvar caml-mode-syntax-table
+  (let ((st (make-syntax-table))
+        (n (if (featurep 'xemacs) "" "n")))
+    ;; backslash is an escape sequence
+    (modify-syntax-entry ?\\ "\\" st)
+    ;; ( is first character of comment start
+    (modify-syntax-entry ?\( (concat "()1" n) st)
+    ;; * is second character of comment start,
+    ;; and first character of comment end
+    (modify-syntax-entry ?*  (concat ". 23" n) st)
+    ;; ) is last character of comment end
+    (modify-syntax-entry ?\) ")(4" st)
+    ;; backquote was a string-like delimiter (for character literals)
+    ;; (modify-syntax-entry ?` "\"" st)
+    ;; quote and underscore are part of words
+    (modify-syntax-entry ?' "w" st)
+    (modify-syntax-entry ?_ "w" st)
+    ;; 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))))))
+        (modify-syntax-entry i "w" st)
+        (setq i (1+ i))))
+    st)
+  "Syntax table in use in Caml mode buffers.")
 
 (defvar caml-mode-abbrev-table nil
   "Abbrev table used for Caml mode buffers.")
@@ -477,17 +473,8 @@ have `caml-electric-indent' on, which see.")
 (defvar caml-mode-hook nil
   "Hook for `caml-mode'.")
 
-(defun caml-mode ()
-  "Major mode for editing OCaml code.
-
-\\{caml-mode-map}"
-
-  (interactive)
-  (kill-all-local-variables)
-  (setq major-mode 'caml-mode)
-  (setq mode-name "caml")
-  (use-local-map caml-mode-map)
-  (set-syntax-table caml-mode-syntax-table)
+(define-derived-mode caml-mode fundamental-mode "caml" ;FIXME: Use `prog-mode'
+  "Major mode for editing OCaml code."
   (setq local-abbrev-table caml-mode-abbrev-table)
   (make-local-variable 'paragraph-start)
   (setq paragraph-start (concat "^$\\|" page-delimiter))
@@ -508,10 +495,10 @@ have `caml-electric-indent' on, which see.")
   (make-local-variable 'parse-sexp-ignore-comments)
   (setq parse-sexp-ignore-comments nil)
   (make-local-variable 'indent-line-function)
-  (setq indent-line-function 'caml-indent-command)
+  (setq indent-line-function #'caml-indent-command)
   ;itz Fri Sep 25 13:23:49 PDT 1998
   (make-local-variable 'add-log-current-defun-function)
-  (setq add-log-current-defun-function 'caml-current-defun)
+  (setq add-log-current-defun-function #'caml-current-defun)
   ;garrigue 27-11-96
   (setq case-fold-search nil)
   ;garrigue july 97
@@ -525,12 +512,11 @@ have `caml-electric-indent' on, which see.")
             (add-submenu nil caml-mode-xemacs-menu)))
     ;imenu support (not for Xemacs)
     (make-local-variable 'imenu-create-index-function)
-    (setq imenu-create-index-function 'caml-create-index-function)
+    (setq imenu-create-index-function #'caml-create-index-function)
     (make-local-variable 'imenu-generic-expression)
     (setq imenu-generic-expression caml-imenu-search-regexp)
     (if (and caml-imenu-enable (< (buffer-size) 10000))
-        (caml-show-imenu)))
-  (run-hooks 'caml-mode-hook))
+        (caml-show-imenu))))
 
 
 ;; Disabled because it assumes make and does not play well with ocamlbuild.
@@ -565,7 +551,7 @@ have `caml-electric-indent' on, which see.")
 ;;             (setq compile-command (concat command " " filename))))
 ;;       )))
 
-;; (add-hook 'caml-mode-hook 'caml-set-compile-command)
+;; (add-hook 'caml-mode-hook #'caml-set-compile-command)
 
 
 ;;; Auxiliary function. Garrigue 96-11-01.
@@ -588,6 +574,7 @@ Send the current region bounded by START and END to the 
inferior
 OCaml process."
   (interactive"r")
   (require 'inf-caml)
+  (declare-function inferior-caml-eval-region "inf-caml")
   (inferior-caml-eval-region start end))
 
 ;; old version ---to be deleted later
@@ -615,6 +602,7 @@ Optional arguments MIN MAX defines a region within which 
the phrase
 should lies."
   (interactive "p")
   (require 'inf-caml)
+  (declare-function inferior-caml-eval-phrase "inf-caml")
   (inferior-caml-eval-phrase arg min max))
 
 (defun caml-eval-buffer (arg)
@@ -633,6 +621,7 @@ stopping at the current point."
   "Start an inferior subshell."
   (interactive)
   (require 'inf-caml)
+  (declare-function inferior-caml-show-subshell "inf-caml")
   (inferior-caml-show-subshell))
 
 
@@ -766,27 +755,6 @@ variable `caml-mode-indentation'."
 ;; Error positions are given in bytes, not in characters
 ;; This function switches to monobyte mode
 
-(if (not (fboundp 'char-bytes))
-    (defalias 'forward-byte 'forward-char)
-  (defun caml-char-bytes (ch)
-    (let ((l (char-bytes ch)))
-      (if (> l 1) (- l 1) l)))
-  (defun forward-byte (count)
-    (if (> count 0)
-        (while (> count 0)
-          (let ((char (char-after)))
-            (if (null char)
-                (setq count 0)
-              (setq count (- count (caml-char-bytes (char-after))))
-              (forward-char))))
-      (while (< count 0)
-        (let ((char (char-after)))
-          (if (null char)
-              (setq count 0)
-            (setq count (+ count (caml-char-bytes (char-before))))
-            (backward-char))))
-    )))
-
 (require 'compile)
 
 ;; In Emacs 19, the regexps in compilation-error-regexp-alist do not
@@ -843,9 +811,8 @@ error message produced by ocamlc.")
 (defvar caml-error-overlay nil)
 (defvar caml-next-error-skip-warnings-flag nil)
 
-(if (fboundp 'string-to-number)
-   (defalias 'caml-string-to-int 'string-to-number)
- (defalias 'caml-string-to-int 'string-to-int))
+(define-obsolete-function-alias 'caml-string-to-int
+  #'string-to-number "Jan 2021")
 
 ;;itz 04-21-96 somebody didn't get the documentation for next-error
 ;;right. When the optional argument is a number n, it should move
@@ -872,10 +839,10 @@ possible."
              (goto-char (window-point (get-buffer-window (current-buffer))))
              (if (looking-at caml-error-chars-regexp)
                  (setq beg
-                       (caml-string-to-int
+                       (string-to-number
                         (buffer-substring (match-beginning 1) (match-end 1)))
                        end
-                       (caml-string-to-int
+                       (string-to-number
                         (buffer-substring (match-beginning 2) (match-end 2)))))
              (forward-line 1)
              (beginning-of-line)
@@ -887,9 +854,9 @@ possible."
         (beg
               (setq end (- end beg))
               (beginning-of-line)
-              (forward-byte beg)
+              (forward-char beg)
               (setq beg (point))
-              (forward-byte end)
+              (forward-char end)
               (setq end (point))
               (goto-char beg)
               (push-mark end t)
@@ -910,7 +877,7 @@ For the arguments ARGS, see `next-error'."
   (let ((old-flag caml-next-error-skip-warnings-flag))
     (unwind-protect
         (progn (setq caml-next-error-skip-warnings-flag 't)
-               (apply 'next-error args))
+               (apply #'next-error args))
       (setq caml-next-error-skip-warnings-flag old-flag))))
 
 
@@ -938,6 +905,7 @@ buffer."
   "Find the error location in current OCaml phrase."
   (interactive)
   (require 'inf-caml)
+  (declare-function inferior-caml-goto-error "inf-caml")
   (let ((bounds (save-excursion (caml-mark-phrase))))
     (inferior-caml-goto-error (car bounds) (cdr bounds))))
 
@@ -985,7 +953,7 @@ MAX-POS."
   (interactive)
   (if (not min-pos) (setq min-pos (point-min)))
   (if (not max-pos) (setq max-pos (point-max)))
-  (let (beg end use-semi kwop)
+  (let (beg end kwop)
     ;(caml-skip-comments-backward)
     (cond
      ; shall we have special processing for semicolons?
@@ -1568,7 +1536,7 @@ Does not preserve point."
             (length (caml-match-string 0)))
            ((nth 1 kwop-info) (symbol-value (nth 3 kwop-info)))
            (t
-            (let ((pos (point)))
+            (let () ;; (pos (point))
               (back-to-indentation)
 ;             (if (looking-at "\\_<let\\_>") (goto-char pos))
               (- (symbol-value (nth 3 kwop-info))
diff --git a/camldebug.el b/camldebug.el
index 8b59942..bd84abc 100644
--- a/camldebug.el
+++ b/camldebug.el
@@ -1,4 +1,4 @@
-;**************************************************************************
+;****************************************** -*- lexical-binding: t; -*- ***
 ;*                                                                        *
 ;*                                 OCaml                                  *
 ;*                                                                        *
@@ -87,6 +87,8 @@
 
 ;;; Camldebug mode.
 
+(defvar comint-input-sentinel)
+
 (define-derived-mode camldebug-mode comint-mode "Inferior CDB"
 
   "Major mode for interacting with an inferior ocamldebug process.
@@ -113,23 +115,22 @@ Additionally we have:
 \\[camldebug-step] advance one line in program
 C-x SPACE sets break point at current line."
 
-  (mapcar 'make-local-variable
-          '(camldebug-last-frame-displayed-p  camldebug-last-frame
-            camldebug-delete-prompt-marker camldebug-filter-function
-           camldebug-filter-accumulator paragraph-start))
+  (mapc #'make-local-variable
+        '(camldebug-last-frame-displayed-p  camldebug-last-frame
+          camldebug-delete-prompt-marker camldebug-filter-function
+          camldebug-filter-accumulator paragraph-start))
   (setq
    camldebug-last-frame nil
    camldebug-delete-prompt-marker (make-marker)
    camldebug-filter-accumulator ""
-   camldebug-filter-function 'camldebug-marker-filter
+   camldebug-filter-function #'camldebug-marker-filter
    comint-prompt-regexp camldebug-prompt-pattern
-   comint-dynamic-complete-functions (cons 'camldebug-complete
-                                           comint-dynamic-complete-functions)
    paragraph-start comint-prompt-regexp
    camldebug-last-frame-displayed-p t)
+  (add-hook 'comint-dynamic-complete-functions #'camldebug-complete nil t)
   (make-local-variable 'shell-dirtrackp)
   (setq shell-dirtrackp t)
-  (setq comint-input-sentinel 'shell-directory-tracker))
+  (setq comint-input-sentinel #'shell-directory-tracker))
 
 ;;; Keymaps.
 
@@ -205,12 +206,15 @@ representation is simply concatenated with the COMMAND."
 
 (define-key camldebug-mode-map [mouse-2] 'camldebug-mouse-display)
 
+(defvar camldebug-kill-output)
+
 (defun camldebug-kill-filter (string)
   ;gob up stupid questions :-)
   (setq camldebug-filter-accumulator
         (concat camldebug-filter-accumulator string))
   (if (not (string-match "\\(.* \\)(y or n) "
-                         camldebug-filter-accumulator)) nil
+                         camldebug-filter-accumulator))
+      nil
     (setq camldebug-kill-output
           (cons t (match-string 1 camldebug-filter-accumulator)))
     (setq camldebug-filter-accumulator ""))
@@ -226,14 +230,17 @@ representation is simply concatenated with the COMMAND."
 
 (def-camldebug "kill"   "\C-k")
 
+(defvar current-camldebug-buffer nil)
+(defvar camldebug-goto-output)
+(defvar camldebug-goto-position)
+
 (defun camldebug-kill ()
   "Kill the program."
   (interactive)
   (let ((camldebug-kill-output))
-    (save-excursion
-      (set-buffer current-camldebug-buffer)
+    (with-current-buffer current-camldebug-buffer
       (let ((proc (get-buffer-process (current-buffer)))
-            (camldebug-filter-function 'camldebug-kill-filter))
+            (camldebug-filter-function #'camldebug-kill-filter))
         (camldebug-call "kill")
         (while (not (and camldebug-kill-output
                          (zerop (length camldebug-filter-accumulator))))
@@ -263,7 +270,8 @@ representation is simply concatenated with the COMMAND."
     (setq camldebug-filter-accumulator
           (substring camldebug-filter-accumulator (1- (match-end 0)))))
   (if (not (string-match comint-prompt-regexp
-                         camldebug-filter-accumulator)) nil
+                         camldebug-filter-accumulator))
+      nil
     (setq camldebug-goto-output (or camldebug-goto-output 'fail))
     (setq camldebug-filter-accumulator ""))
   (if (string-match "\n\\(.*\\)\\'" camldebug-filter-accumulator)
@@ -303,18 +311,17 @@ buffer, then try to obtain the time from context around 
point."
                    ((save-excursion
                       (beginning-of-line 1)
                       (looking-at "^Time : \\([0-9]+\\) - pc : [0-9]+ "))
-                    (caml-string-to-int (match-string 1)))
-                   ((caml-string-to-int (camldebug-format-command "%e"))))))
+                    (string-to-number (match-string 1)))
+                   ((string-to-number (camldebug-format-command "%e"))))))
         (camldebug-call "goto" nil time)))
    (t
     (let ((module (camldebug-module-name (buffer-file-name)))
           (camldebug-goto-position (int-to-string (1- (point))))
           (camldebug-goto-output) (address))
       ;get a list of all events in the current module
-      (save-excursion
-        (set-buffer current-camldebug-buffer)
+      (with-current-buffer current-camldebug-buffer
         (let* ((proc (get-buffer-process (current-buffer)))
-               (camldebug-filter-function 'camldebug-goto-filter))
+               (camldebug-filter-function #'camldebug-goto-filter))
           (camldebug-call-1 (concat "info events " module))
           (while (not (and camldebug-goto-output
                       (zerop (length camldebug-filter-accumulator))))
@@ -324,11 +331,15 @@ buffer, then try to obtain the time from context around 
point."
                            (concat "^Time : \\([0-9]+\\) - pc : "
                                    camldebug-goto-output
                                    " - module "
-                                   module "$") nil t)
+                                   module "$")
+                           nil t)
                           (match-string 1)))))
-      (if address (camldebug-call "goto" nil (caml-string-to-int address))
+      (if address (camldebug-call "goto" nil (string-to-number address))
         (error "No time at %s at %s" module camldebug-goto-position))))))
 
+(defvar camldebug-delete-output)
+(defvar camldebug-delete-position)
+(defvar camldebug-delete-file)
 
 (defun camldebug-delete-filter (string)
   (setq camldebug-filter-accumulator
@@ -338,13 +349,15 @@ buffer, then try to obtain the time from context around 
point."
                     (regexp-quote camldebug-delete-file)
                     ", character "
                     camldebug-delete-position "\n")
-                  camldebug-filter-accumulator)) nil
+            camldebug-filter-accumulator))
+      nil
     (setq camldebug-delete-output
           (match-string 2 camldebug-filter-accumulator))
     (setq camldebug-filter-accumulator
           (substring camldebug-filter-accumulator (1- (match-end 0)))))
   (if (not (string-match comint-prompt-regexp
-                         camldebug-filter-accumulator)) nil
+                         camldebug-filter-accumulator))
+      nil
     (setq camldebug-delete-output (or camldebug-delete-output 'fail))
     (setq camldebug-filter-accumulator ""))
   (if (string-match "\n\\(.*\\)\\'" camldebug-filter-accumulator)
@@ -372,8 +385,7 @@ around point."
    (arg
     (let ((narg (camldebug-numeric-arg arg)))
       (if (> narg 0) (camldebug-call "delete" nil narg)
-        (save-excursion
-          (set-buffer current-camldebug-buffer)
+        (with-current-buffer current-camldebug-buffer
           (if (re-search-backward "^Breakpoint [0-9]+ at [0-9]+ : file "
                                   nil t (- 1 narg))
               (camldebug-delete nil)
@@ -384,21 +396,20 @@ around point."
            (arg (cond
                  ((eobp)
                   (save-excursion (re-search-backward bpline nil t))
-                  (caml-string-to-int (match-string 1)))
+                  (string-to-number (match-string 1)))
                  ((save-excursion
                     (beginning-of-line 1)
                     (looking-at bpline))
-                  (caml-string-to-int (match-string 1)))
-                 ((caml-string-to-int (camldebug-format-command "%e"))))))
+                  (string-to-number (match-string 1)))
+                 ((string-to-number (camldebug-format-command "%e"))))))
       (camldebug-call "delete" nil arg)))
    (t
     (let ((camldebug-delete-file
            (concat (camldebug-format-command "%m") ".ml"))
           (camldebug-delete-position (camldebug-format-command "%c")))
-      (save-excursion
-        (set-buffer current-camldebug-buffer)
+      (with-current-buffer current-camldebug-buffer
         (let ((proc (get-buffer-process (current-buffer)))
-              (camldebug-filter-function 'camldebug-delete-filter)
+              (camldebug-filter-function #'camldebug-delete-filter)
               (camldebug-delete-output))
           (camldebug-call-1 "info break")
           (while (not (and camldebug-delete-output
@@ -410,21 +421,23 @@ around point."
                      camldebug-delete-file
                      camldebug-delete-position)
             (camldebug-call "delete" nil
-                            (caml-string-to-int 
camldebug-delete-output)))))))))
+                            (string-to-number camldebug-delete-output)))))))))
+
+(defvar camldebug-complete-list)
 
 (defun camldebug-complete-filter (string)
   (setq camldebug-filter-accumulator
         (concat camldebug-filter-accumulator string))
   (while (string-match "\\(\n\\|\\`\\)\\(.+\\)\n"
                        camldebug-filter-accumulator)
-    (setq camldebug-complete-list
-          (cons (match-string 2 camldebug-filter-accumulator)
-                camldebug-complete-list))
+    (push (match-string 2 camldebug-filter-accumulator)
+          camldebug-complete-list)
     (setq camldebug-filter-accumulator
           (substring camldebug-filter-accumulator
                      (1- (match-end 0)))))
   (if (not (string-match comint-prompt-regexp
-                         camldebug-filter-accumulator)) nil
+                         camldebug-filter-accumulator))
+      nil
     (setq camldebug-complete-list
           (or camldebug-complete-list 'fail))
     (setq camldebug-filter-accumulator ""))
@@ -458,7 +471,7 @@ around point."
     (if (> (length command-word) 0)
         (setq command (substring command 0 (1- (length command)))))
 
-    (let ((camldebug-filter-function 'camldebug-complete-filter))
+    (let ((camldebug-filter-function #'camldebug-complete-filter))
       (camldebug-call-1 (concat "complete " command))
       (set-marker camldebug-delete-prompt-marker nil)
       (while (not (and camldebug-complete-list
@@ -478,9 +491,6 @@ around point."
 (define-key caml-mode-map "\C-x " 'camldebug-break)
 
 
-(defvar current-camldebug-buffer nil)
-
-
 ;;;###autoload
 (defvar camldebug-command-name "ocamldebug"
   "*Pathname for executing camldebug.")
@@ -526,13 +536,14 @@ the camldebug commands `cd DIR' and `directory'."
                   camldebug-filter-accumulator))
       (setq camldebug-last-frame
             (if (char-equal ?H (aref camldebug-filter-accumulator
-                                     (1+ (1+ begin)))) nil
+                                     (1+ (1+ begin))))
+                nil
               (let ((isbefore
                      (string= "before"
                               (match-string 5 camldebug-filter-accumulator)))
-                    (startpos (caml-string-to-int
+                    (startpos (string-to-number
                                (match-string 3 camldebug-filter-accumulator)))
-                    (endpos (caml-string-to-int
+                    (endpos (string-to-number
                              (match-string 4 camldebug-filter-accumulator))))
                 (list (match-string 2 camldebug-filter-accumulator)
                       (if isbefore startpos endpos)
@@ -578,8 +589,7 @@ the camldebug commands `cd DIR' and `directory'."
           ;; since set-buffer as a temporary effect.
           ;; comint-output-filter explicitly avoids it.
           ;; in version 23, it prevents the marker to stay at end of buffer
-          ;; (save-excursion
-            (set-buffer (process-buffer proc))
+          (with-current-buffer (process-buffer proc)
             ;; If we have been so requested, delete the debugger prompt.
             (if (marker-buffer camldebug-delete-prompt-marker)
                 (progn
@@ -595,9 +605,7 @@ the camldebug commands `cd DIR' and `directory'."
                                       (>= (point) (process-mark proc))
                                       (get-buffer-window (current-buffer))))
             ;; Insert the text, moving the process-marker.
-            (comint-output-filter proc output)
-          ;; )
-          ;; this was the end of save-excursion.
+            (comint-output-filter proc output))
           ;; if save-excursion is used (comint-next-prompt 1) would be needed
           ;; to move the mark past then next prompt, but this is not as good
           ;; as solution.
@@ -666,14 +674,15 @@ Obeying it means displaying in another window the 
specified file and line."
 ;; and that its character CHARACTER is visible.
 ;; Put the mark on this character in that buffer.
 
+(defvar pre-display-buffer-function)
+
 (defun camldebug-display-line (true-file schar echar kind)
   (let* ((pre-display-buffer-function nil) ; screw it, put it all in one screen
          (pop-up-windows t)
          (buffer (find-file-noselect true-file))
          (window (display-buffer buffer t))
          (spos) (epos) (pos))
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (save-restriction
         (widen)
         (setq spos (+ (point-min) schar))
@@ -703,8 +712,7 @@ Obeying it means displaying in another window the specified 
file and line."
                           (+ spos 1) epos buffer))
         (move-overlay camldebug-overlay-event (1- epos) epos buffer)
         (move-overlay camldebug-overlay-under spos (- epos 1) buffer))
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (goto-char spos)
       (beginning-of-line)
       (move-marker camldebug-event-marker (point))
@@ -716,10 +724,10 @@ Obeying it means displaying in another window the 
specified file and line."
   (substring filename (string-match "\\([^/]*\\)\\.ml$" filename)
              (match-end 1)))
 
-;;; The camldebug-call function must do the right thing whether its
-;;; invoking keystroke is from the camldebug buffer itself (via
-;;; major-mode binding) or a caml buffer.  In the former case, we want
-;;; to supply data from camldebug-last-frame.  Here's how we do it:
+;; The camldebug-call function must do the right thing whether its
+;; invoking keystroke is from the camldebug buffer itself (via
+;; major-mode binding) or a caml buffer.  In the former case, we want
+;; to supply data from camldebug-last-frame.  Here's how we do it:
 
 (defun camldebug-format-command (str)
   (let* ((insource (not (eq (current-buffer) current-camldebug-buffer)))
@@ -775,10 +783,9 @@ representation is simply concatenated with the COMMAND."
 (defun camldebug-call-1 (command &optional fmt arg)
 
   ;; Record info on the last prompt in the buffer and its position.
-  (save-excursion
-    (set-buffer current-camldebug-buffer)
+  (with-current-buffer current-camldebug-buffer
     (goto-char (process-mark (get-buffer-process current-camldebug-buffer)))
-    (let ((pt (point)))
+    (let () ;;(pt (point))
       (beginning-of-line)
       (if (looking-at comint-prompt-regexp)
           (set-marker camldebug-delete-prompt-marker (point)))))
diff --git a/inf-caml.el b/inf-caml.el
index 3d2b2dc..0e97da0 100644
--- a/inf-caml.el
+++ b/inf-caml.el
@@ -1,4 +1,4 @@
-;**************************************************************************
+;****************************************** -*- lexical-binding: t; -*- ***
 ;*                                                                        *
 ;*                                 OCaml                                  *
 ;*                                                                        *
@@ -32,28 +32,22 @@
 ;; End of User modifiable variables
 
 
-(defvar inferior-caml-mode-map nil)
-(if inferior-caml-mode-map nil
-  (setq inferior-caml-mode-map
-        (copy-keymap comint-mode-map)))
+(defvar inferior-caml-mode-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map comint-mode-map)
+    map))
 
 ;; Augment Caml mode, so you can process OCaml code in the source files.
 
 (defvar inferior-caml-program "ocaml"
   "*Program name for invoking an inferior OCaml from Emacs.")
 
-(defun inferior-caml-mode ()
+(define-derived-mode inferior-caml-mode comint-mode "Inferior-Caml"
   "Major mode for interacting with an inferior OCaml process.
 Runs an OCaml toplevel as a subprocess of Emacs, with I/O through an
 Emacs buffer. A history of input phrases is maintained. Phrases can
-be sent from another buffer in Caml mode.
-
-\\{inferior-caml-mode-map}"
-  (interactive)
-  (comint-mode)
+be sent from another buffer in Caml mode."
   (setq comint-prompt-regexp "^# ?")
-  (setq major-mode 'inferior-caml-mode)
-  (setq mode-name "Inferior Caml")
   (make-local-variable 'paragraph-start)
   (setq paragraph-start (concat "^$\\|" page-delimiter))
   (make-local-variable 'paragraph-separate)
@@ -72,9 +66,11 @@ be sent from another buffer in Caml mode.
   (setq comment-start-skip "(\\*+ *")
   (make-local-variable 'parse-sexp-ignore-comments)
   (setq parse-sexp-ignore-comments nil)
-  (use-local-map inferior-caml-mode-map)
+  ;; Hook names should end in `-hook', not `-hooks'!
   (run-hooks 'inferior-caml-mode-hooks))
 
+(make-obsolete-variable 'inferior-caml-mode-hooks
+                        'inferior-caml-mode-hook "Jan 2021")
 
 (defconst inferior-caml-buffer-subname "inferior-caml")
 (defconst inferior-caml-buffer-name
@@ -83,9 +79,7 @@ be sent from another buffer in Caml mode.
 ;; for compatibility with xemacs
 
 (defun caml-sit-for (second &optional mili redisplay)
-   (if (and (boundp 'running-xemacs) running-xemacs)
-       (sit-for (if mili (+ second (* mili 0.001)) second) redisplay)
-     (sit-for second mili redisplay)))
+  (sit-for (if mili (+ second (* mili 0.001)) second) redisplay))
 
 ;; To show result of evaluation at toplevel
 
@@ -97,7 +91,8 @@ be sent from another buffer in Caml mode.
   (set-variable 'comint-output-filter-functions
         (list (function inferior-caml-signal-output))
         t))
-(add-hook 'inferior-caml-mode-hooks 'inferior-caml-mode-output-hook)
+;; FIXME: Why not put that directly in the major mode function?
+(add-hook 'inferior-caml-mode-hook #'inferior-caml-mode-output-hook)
 
 ;; To launch ocaml whenever needed
 
@@ -152,8 +147,8 @@ Input and output via buffer `*inferior-caml*'."
   (caml-run-process-if-needed)
   (display-buffer inferior-caml-buffer-name)
   ; Added by Didier to move the point of inferior-caml to end of buffer
-  (let ((buf (current-buffer))
-        (caml-buf  (get-buffer inferior-caml-buffer-name))
+  (let (;; (buf (current-buffer))
+        ;; (caml-buf  (get-buffer inferior-caml-buffer-name))
         (count 0))
     (while
         (and (< count 10)
@@ -192,16 +187,15 @@ Input and output via buffer `*inferior-caml*'."
 
 ;; jump to errors produced by ocaml compiler
 
-(defun inferior-caml-goto-error (start end)
+(defun inferior-caml-goto-error (start _end)
   "Jump to the location of the last error as indicated by inferior toplevel."
   (interactive "r")
   (let ((loc (+ start
-                (save-excursion
-                  (set-buffer (get-buffer inferior-caml-buffer-name))
+                (with-current-buffer (get-buffer inferior-caml-buffer-name)
                   (re-search-backward
                    (concat comint-prompt-regexp
                            "[ \t]*Characters[ \t]+\\([0-9]+\\)-[0-9]+:$"))
-                  (caml-string-to-int (match-string 1))))))
+                  (string-to-number (match-string 1))))))
     (goto-char loc)))
 
 
@@ -265,14 +259,14 @@ should lies."
           (cond ((re-search-forward
                   " *Characters \\([01-9][01-9]*\\)-\\([1-9][01-9]*\\):\n[^W]"
                   (point-max) t)
-                 (setq beg (caml-string-to-int (caml-match-string 1)))
-                 (setq end (caml-string-to-int (caml-match-string 2)))
+                 (setq beg (string-to-number (caml-match-string 1)))
+                 (setq end (string-to-number (caml-match-string 2)))
                  (switch-to-buffer buf)
                  (goto-char orig)
-                 (forward-byte end)
+                 (forward-char end)
                  (setq end (point))
                  (goto-char orig)
-                 (forward-byte beg)
+                 (forward-char beg)
                  (setq beg (point))
                  (setq err beg)
                  )
@@ -337,12 +331,11 @@ should lies."
 ;; waiting, i.e. may report 'No result yet'
 
 (defun caml-wait-output (&optional before after)
+  (caml-sit-for 0 (or before 1))
   (let ((c 1))
-    (caml-sit-for 0 (or before 1))
-    (let ((c 1))
-      (while (and (not inferior-caml-output) (< c 99) (caml-sit-for 0 c t))
-        (setq c (+ c 1))))
-    (caml-sit-for (or after 0) 1)))
+    (while (and (not inferior-caml-output) (< c 99) (caml-sit-for 0 c t))
+      (setq c (+ c 1))))
+  (caml-sit-for (or after 0) 1))
 
 ;; To insert the last output from caml at point
 (defun caml-insert-last-output ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]