-
Notifications
You must be signed in to change notification settings - Fork 2
/
pjb-clelp.el
89 lines (83 loc) · 3.41 KB
/
pjb-clelp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;;;; -*- mode:emacs-lisp;coding:utf-8 -*-
;;;;**************************************************************************
;;;;FILE: pjb-clelp.el
;;;;LANGUAGE: emacs lisp
;;;;SYSTEM: POSIX
;;;;USER-INTERFACE: NONE
;;;;DESCRIPTION
;;;;
;;;; Helpers for CL development.
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
;;;;MODIFICATIONS
;;;; 2020-10-21 <PJB> Created
;;;;BUGS
;;;;LEGAL
;;;; AGPL3
;;;;
;;;; Copyright Pascal J. Bourguignon 2020 - 2020
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Affero General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU Affero General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;**************************************************************************
(require 'cl)
(require 'slime)
(require 'pjb-cl)
(defun* pjb-find-file-not-found/cl-pathname ()
"Resolve the `buffer-file-name' thru common-lisp via slime,
and insert the file contents when found.
This allows to find-file on CL logical-pathnames,
as displayed eg. in ccl error messages.
Compiler warnings for \"home:foo;bar;baz.lisp.newest\" :
You can then C-x C-f and yank:
home:foo;bar;baz.lisp.newest
\"home:foo;bar;baz.lisp.newest\"
even after a prefix path.
"
(with-current-buffer (current-buffer)
(when (slime-connected-p)
(flet ((clpath (path)
(slime-eval
`(cl:or (cl:ignore-errors
(cl:namestring
(cl:truename
(cl:pathname ,path))))
(cl:ignore-errors
(cl:namestring
(cl:truename
(cl:make-pathname :version nil :defaults (cl:pathname ,path)))))))))
(let ((path (clpath buffer-file-name)))
(unless (and path (file-exists-p path))
(when (or (string-match "^ *\"\\([^/]+\\)\"$" buffer-file-name)
(string-match "^/.*/ *\"\\([^/]+\\)\"$" buffer-file-name)
(string-match "^/.*/ *\\([^/]+\\)$" buffer-file-name))
(setf path (clpath (match-string 1 buffer-file-name)))))
(when (and path (file-exists-p path))
(let ((old-buffer (find-buffer-visiting path)))
(if old-buffer
(progn
(kill-buffer (current-buffer))
(switch-to-buffer old-buffer)
t)
(handler-case
(let ((inhibit-read-only t))
(insert-file-contents path)
(set-visited-file-name path)
(message "buffer-file-name = %S" path)
t)
(file-error ()
nil))))))))))
(add-hook 'find-file-not-found-functions 'pjb-find-file-not-found/cl-pathname)
(provide 'pjb-clelp)
;;;; THE END ;;;;