Subject: Re: [PATCH] Add support for Vi/Vim modelines.

From: James Youngman <[email-masked]>
Date: Thu, 17 Jul 2025 10:53:45 +0100

Apologies, I think this broke "make check".  Here are the needed fixes.
From e576780a457558aaeb85f74bf3f621991e564f34 Mon Sep 17 00:00:00 2001
From: James Youngman <[email-masked]>
Date: Thu, 17 Jul 2025 10:51:15 +0100
Subject: [PATCH 2/2] Fix docstrings, requires, avoid deprecated functions in
 vimvars.

---
 lisp/emulation/vimvars.el            | 20 +++++++++++++-------
 test/lisp/emulation/vimvars-tests.el | 26 +++++++-------------------
 2 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/lisp/emulation/vimvars.el b/lisp/emulation/vimvars.el
index 50b56cc6912..417b1c4800c 100644
--- a/lisp/emulation/vimvars.el
+++ b/lisp/emulation/vimvars.el
@@ -1,4 +1,4 @@
-;;; vimvars.el --- Emacs support for Vi modelines
+;;; vimvars.el --- Emacs support for Vi modelines   -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2010,2011,2025 Free Software Foundation, Inc.
 
@@ -31,6 +31,11 @@
 ;;; uses "Vi"), instead of "VIM" which is what that editor's
 ;;; documentation uses as its name.
 
+(require 'simple)                       ; needed for read-only-mode
+(require 'cc-bytecomp)                  ; needed for cc-require
+(cc-require 'cc-vars)                   ; we use c-basic-offset.
+
+
 (defgroup vimvars nil
   "Support for Vim mode lines."
   :version "31.1"
@@ -46,7 +51,8 @@ vimvars-enabled

 (defcustom vimvars-check-lines 5
-  "The number of lines in the top or bottom of a file that we will search for Vim settings (Vim itself checks 5)."
+  "The number of lines in the top or bottom of a file that we will search for
+ Vim settings (Vim itself checks 5 by default)."
   :version "31.1"
   :type 'integer
   :group 'vimvars)
@@ -71,7 +77,7 @@ vimvars-obey-vim-modeline
 Only the first and last `vimvars-check-lines' lines of the file
 are checked for Vim variables.   You can use this in `find-file-hook'.
 
-One enables modelines in Vim by putting 'set modeline' in the
+One enables modelines in Vim by putting `set modeline' in the
 .vimrc file."
   (when (vimvars--should-obey-modeline)
     (save-excursion
@@ -191,20 +197,20 @@ vimvars--enable-feature
   (cond
    ((equal var "expandtab") (setq indent-tabs-mode nil))
    ((equal var "ignorecase") (setq case-fold-search t))
-   ((equal var "readonly") (toggle-read-only 1))
+   ((equal var "readonly") (read-only-mode 1))
    ((equal var "wrap") (setq truncate-lines nil))
-   ((equal var "write") (toggle-read-only -1)) ; See nowrite below.
+   ((equal var "write") (read-only-mode -1)) ; See nowrite below.
 
    ((equal var "noexpandtab") (setq indent-tabs-mode t))
    ((equal var "noignorecase") (setq case-fold-search nil))
-   ((equal var "noreadonly") (toggle-read-only -1))
+   ((equal var "noreadonly") (read-only-mode -1))
    ((equal var "nowrap") (setq truncate-lines t))
 
    ;; In Vim, setting 'nowrite' option creates a situation
    ;; in which editing the file generates no warning (unlike
    ;; 'set readonly') but by default attempts to save the
    ;; file (even to a new file name) generate a warning.
-   ((equal var "nowrite") (toggle-read-only 1)) ; Similar, not the same
+   ((equal var "nowrite") (read-only-mode 1)) ; Similar, not the same
 
    (t (message "Don't know how to emulate Vim feature %s" var))))
 
diff --git a/test/lisp/emulation/vimvars-tests.el b/test/lisp/emulation/vimvars-tests.el
index bc0efdb3658..6516a6636d2 100644
--- a/test/lisp/emulation/vimvars-tests.el
+++ b/test/lisp/emulation/vimvars-tests.el
@@ -1,4 +1,4 @@
-;;; vimvars-tests.el --- Tests for vimvars.el
+;;; vimvars-tests.el --- Tests for vimvars.el   -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2011,2025 Free Software Foundation, Inc.
 
@@ -17,6 +17,7 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with vimvars.  If not, see <http://www.gnu.org/licenses/>.
+(require 'vimvars)
 
 (ert-deftest vimvars-test-modeline-accept-vim-vi-bol ()
   "Check we accept 'vim:' or 'vi:' at beginning of line.
@@ -91,8 +92,8 @@ vimvars-test-nonexpansions
 
 (defun kill-buffers-visiting (filename)
   (while
-      (let (existing (get-file-buffer filename))
-           (when existing (kill-buffer existing)))))
+      (let ((existing (get-file-buffer filename)))
+        (when existing (kill-buffer existing)))))
 
 (defmacro vimvars-tests--run-checks-for-file-body (suffix content &rest checks)
   "Write a temporary file whose name has suffix SUFFIX, having content CONTENT.
@@ -104,7 +105,7 @@ vimvars-tests--run-checks-for-file-body
               (old-vimvars-check-lines vimvars-check-lines)
               (old-default-fill-column (default-value 'fill-column))
               (old-tab-width (default-value 'tab-width))
-              (old-find-file-hooks find-file-hooks))
+              (old-find-file-hook find-file-hook))
        (unwind-protect
               (progn
                       ;; Set up a standard testing environment (choosing
@@ -129,7 +130,7 @@ vimvars-tests--run-checks-for-file-body
                  (setq-default fill-column old-default-fill-column
                                      tab-width old-tab-width)
                  (setq vimvars-check-lines old-vimvars-check-lines
-                          find-file-hooks old-find-file-hooks))))))
+                          find-file-hook old-find-file-hook))))))
 
 (defmacro vimvars-tests--run-checks-for-text-file (content &rest checks)
   "Calls vimvars-tests--run-checks-for-file-body with SUFFIX set to .txt."
@@ -205,7 +206,7 @@ vimvars-test-makeprg
    (should (equal compile-command "gmake"))))

-(defun vimvars-test-check-recognise-modeline (description modeline)
+(defun vimvars-test-check-recognise-modeline (modeline)
   (let ((actual-modeline (concat modeline "\n")))
     (vimvars-tests--run-checks-for-text-file
      actual-modeline
@@ -214,71 +215,58 @@ vimvars-test-check-recognise-modeline
 
 (ert-deftest vimvars-test-modeline-accept-vim-set ()
     (vimvars-test-check-recognise-modeline
-     "test-accept-vim-set"
      "# vim: set ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-vi-set ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-vi-set"
    "# vi: set ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-ex-set ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-ex-set"
    "# ex: set ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-vim-se ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-vim-se"
    "# vim: se ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-vi-se ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-vi-se"
    "# vi: se ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-ex-se ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-ex-se"
    "# ex: se ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-vim-setlocal ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-vim-setlocal"
    "# vim: setlocal ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-vi-setlocal ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-vi-setlocal"
    "# vi: setlocal ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-ex-setlocal ()
   (vimvars-test-check-recognise-modeline
-   "test-accept-ex-setlocal"
    "# ex: setlocal ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-no-space-before-final-colon ()
   "Check modelines work even without a space before the final colon."
   (vimvars-test-check-recognise-modeline
-   "test-accept-no-space-before-final-colon"
    "# vi: set ts=18:\n"))
 
 (ert-deftest vimvars-test-modeline-accept-extra-spaces ()
   "Check extra spaces before vi: are accepted"
   (vimvars-test-check-recognise-modeline
-   "test-accept-extra-spaces"
    "#   vi: set ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-tab ()
   "Check tabs before vi: are accepted."
   (vimvars-test-check-recognise-modeline
-   "test-accept-tab"
    "#\tvi: set ts=18 :\n"))
 
 (ert-deftest vimvars-test-modeline-accept-vi-at-start ()
   "Check vi: at the start of the line is accepted"
   (vimvars-test-check-recognise-modeline
-   "test-accept-vi-at-start"
    "vi: set ts=18 :\n"))
 
 (defmacro vimvars-tests--with-temp-default (varname temp-value &rest body)
-- 
2.39.5