branch: elpa/racket-mode
commit 972373bada4de65a01940a76eb6fcb02afdaf1bc
Author: Greg Hendershott <[email protected]>
Commit: Greg Hendershott <[email protected]>

    Fix problems with racket-project-root; closes #752
    
    1. Use project-root -- or, in older Emacs (car project-roots) -- to
    extract the directory from the value returned by project-current.
    
    Don't use cdr, which assumes a representation not necessarily true for
    all project back ends.
    
    2. Stop using vc-root-dir.
    
    AFAICT, this was never appropriate, because it works in terms of the
    current buffer -- using it ignores the FILE argument supplied to
    racket-project-root. WTH was I thinking, years ago??
    
    This simplifies racket-project-root to using the popular third-party
    package "projectile" when available, else the built-in "project"
    library when it can return a directory, else a final fallback of using
    file-name-directory.
---
 doc/racket-mode.texi       | 10 +++++-----
 racket-repl-buffer-name.el |  4 ++--
 racket-util.el             | 21 +++++++++++++--------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/doc/racket-mode.texi b/doc/racket-mode.texi
index 01b562da53..d3b260537c 100644
--- a/doc/racket-mode.texi
+++ b/doc/racket-mode.texi
@@ -979,6 +979,8 @@ from @code{racket} lang and popular modules like 
@code{racket/match}.
 Indentation uses rules for a fixed set of forms, and may be
 customized.
 
+See also @ref{racket-hash-lang-mode}.
+
 @multitable 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
 {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
 @item Key
 @tab Binding
@@ -4000,7 +4002,7 @@ A value for the variable 
@ref{racket-repl-buffer-name-function}.
 @code{(racket-repl-buffer-name-project)}
 
 
-Share a @ref{racket-repl-mode} buffer per back end and per project.
+Share one @ref{racket-repl-mode} buffer per back end and per project.
 
 A value for the variable @ref{racket-repl-buffer-name-function}.
 
@@ -4018,11 +4020,9 @@ The ``project'' is determined by trying, in order:
 
 @itemize
 @item
-@code{projectile-project-root}
-@item
-@code{vc-root-dir}
+@code{projectile-project-root}, if that exists
 @item
-@code{project-current}
+@code{project-current} and @code{project-root}
 @item
 @code{file-name-directory}
 @end itemize
diff --git a/racket-repl-buffer-name.el b/racket-repl-buffer-name.el
index c025e4f6fc..39261d8384 100644
--- a/racket-repl-buffer-name.el
+++ b/racket-repl-buffer-name.el
@@ -1,6 +1,6 @@
 ;;; racket-repl-buffer-name.el -*- lexical-binding: t; -*-
 
-;; Copyright (c) 2013-2023 by Greg Hendershott.
+;; Copyright (c) 2013-2025 by Greg Hendershott.
 ;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: Greg Hendershott
@@ -45,7 +45,7 @@ A value for the variable `racket-repl-buffer-name-function'."
 
 ;;;###autoload
 (defun racket-repl-buffer-name-project ()
-  "Share a `racket-repl-mode' buffer per back end and per project.
+  "Share one `racket-repl-mode' buffer per back end and per project.
 
 A value for the variable `racket-repl-buffer-name-function'.
 
diff --git a/racket-util.el b/racket-util.el
index 4668f2a2fe..23d903858a 100644
--- a/racket-util.el
+++ b/racket-util.el
@@ -1,6 +1,6 @@
 ;;; racket-util.el -*- lexical-binding: t -*-
 
-;; Copyright (c) 2013-2022 by Greg Hendershott.
+;; Copyright (c) 2013-2025 by Greg Hendershott.
 ;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: Greg Hendershott
@@ -8,6 +8,7 @@
 
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 
+(require 'project)
 (require 'subr-x)
 (require 'racket-custom)
 
@@ -106,19 +107,23 @@ When installed as a package, this can be found from the 
variable
 
 The \"project\" is determined by trying, in order:
 
-- `projectile-project-root'
-- `vc-root-dir'
+- `projectile-project-root', if that exists
 - `project-current'
 - `file-name-directory'"
-  (let ((dir (if file
+  (let ((dir (if (and (stringp file)
+                      (file-exists-p file))
                  (file-name-directory file)
                default-directory)))
     (or (and (fboundp 'projectile-project-root)
              (projectile-project-root dir))
-        (and (fboundp 'vc-root-dir)
-             (vc-root-dir))
-        (and (fboundp 'project-current)
-             (cdr (project-current nil dir)))
+        (when-let (pr (project-current nil dir))
+          ;; In newer Emacs `project-root' is defined; `project-roots'
+          ;; is deprecated (and someday may disappear). We check both
+          ;; with `fboundp' here, in order to work correctly and to
+          ;; please byte compiler on older, current, and future
+          ;; versions of Emacs.
+          (cond ((fboundp 'project-root)  (project-root pr))
+                ((fboundp 'project-roots) (car (project-roots pr)))))
         dir)))
 
 (defun racket--edit-mode-p ()

Reply via email to