Skip to content

Commit 20586fd

Browse files
committed
Fix lint warnings and add test
1 parent 560776f commit 20586fd

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ individual faces with `M-x customize-face`.
323323
| Command | Description |
324324
|--------------------------------|----------------------------------------------|
325325
| `M-x ghostel` | Open a new terminal |
326+
| `M-x ghostel-project` | Open a terminal in the current project root |
326327
| `M-x ghostel-other` | Switch to next terminal or create one |
327328
| `M-x ghostel-clear` | Clear screen and scrollback |
328329
| `M-x ghostel-clear-scrollback` | Clear scrollback only |
@@ -337,6 +338,16 @@ individual faces with `M-x customize-face`.
337338
| `M-x ghostel-download-module` | Download pre-built native module |
338339
| `M-x ghostel-module-compile` | Compile native module from source |
339340

341+
### Project integration
342+
343+
`ghostel-project` opens a terminal in the current project's root directory
344+
with a project-prefixed buffer name. To make it available from
345+
`project-switch-project` (`C-x p p`):
346+
347+
```elisp
348+
(add-to-list 'project-switch-commands '(ghostel-project "Ghostel") t)
349+
```
350+
340351
## Running Tests
341352

342353
Tests use ERT. The Makefile provides convenient targets:

ghostel.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; URL: https://github.com/dakra/ghostel
77
;; Version: 0.7.1
88
;; Keywords: terminals
9-
;; Package-Requires: ((emacs "27.1"))
9+
;; Package-Requires: ((emacs "28.1"))
1010
;; SPDX-License-Identifier: GPL-3.0-or-later
1111

1212
;; This file is NOT part of GNU Emacs.
@@ -78,6 +78,7 @@
7878
;;; Code:
7979

8080
(require 'cl-lib)
81+
(require 'project)
8182
(require 'term)
8283
(require 'url-parse)
8384
(require 'face-remap)
@@ -1977,11 +1978,13 @@ wheel events reach ghostel's own scroll commands."
19771978
;;;###autoload
19781979
(defun ghostel-project ()
19791980
"Create a new Ghostel terminal in the current project's root.
1980-
The buffer name is prefixed with the project name."
1981+
The buffer name is prefixed with the project name.
1982+
To add this to `project-switch-commands':
1983+
(add-to-list \\='project-switch-commands \\='(ghostel-project \"Ghostel\") t)"
19811984
(interactive)
19821985
(let ((default-directory (project-root (project-current t)))
1983-
(ghostel-buffer-name (project-prefixed-buffer-name
1984-
(string-replace "*" "" ghostel-buffer-name))))
1986+
(ghostel-buffer-name (project-prefixed-buffer-name
1987+
(string-trim ghostel-buffer-name "*" "*"))))
19851988
(ghostel)))
19861989

19871990
(defun ghostel-other ()

test/ghostel-test.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,30 @@ cell, so the visual line width must equal the terminal column count."
11551155
(kill-local-variable 'global-hl-line-mode))
11561156
(kill-buffer buf)))))
11571157

1158+
;; -----------------------------------------------------------------------
1159+
;; Test: ghostel-project buffer naming
1160+
;; -----------------------------------------------------------------------
1161+
1162+
(ert-deftest ghostel-test-project-buffer-name ()
1163+
"Test that `ghostel-project' derives the buffer name correctly."
1164+
(require 'project)
1165+
(let ((ghostel-buffer-name "*ghostel*")
1166+
result)
1167+
;; Stub project-current, project-root, and ghostel to capture args
1168+
(cl-letf (((symbol-function 'project-current)
1169+
(lambda (_maybe-prompt) '(transient . "/tmp/myproj/")))
1170+
((symbol-function 'project-root)
1171+
(lambda (proj) (cdr proj)))
1172+
((symbol-function 'ghostel)
1173+
(lambda ()
1174+
(setq result (cons default-directory ghostel-buffer-name)))))
1175+
(ghostel-project)
1176+
;; default-directory should be the project root
1177+
(should (equal "/tmp/myproj/" (car result)))
1178+
;; Buffer name should be project-prefixed (no raw asterisks passed)
1179+
(should (string-match-p "ghostel" (cdr result)))
1180+
(should-not (string-match-p "\\*\\*" (cdr result))))))
1181+
11581182
;; -----------------------------------------------------------------------
11591183
;; Runner
11601184
;; -----------------------------------------------------------------------
@@ -1420,6 +1444,7 @@ cell, so the visual line width must equal the terminal column count."
14201444
ghostel-test-osc51-eval-unknown
14211445
ghostel-test-copy-mode-cursor
14221446
ghostel-test-copy-mode-hl-line
1447+
ghostel-test-project-buffer-name
14231448
ghostel-test-package-version
14241449
ghostel-test-module-version-match
14251450
ghostel-test-module-version-mismatch

0 commit comments

Comments
 (0)