Skip to content

Commit

Permalink
Merge pull request #1658 from lem-project/read-only-sources
Browse files Browse the repository at this point in the history
open the source code of the sbcl as read-only
  • Loading branch information
cxxxr authored Nov 30, 2024
2 parents 86d9f36 + ce7d74a commit 32a1d12
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions extensions/lisp-mode/connection.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:connection-command
:connection-process
:connection-process-directory
:connection-system-file-patterns
:connection-plist
:self-connection-p)
(:export :new-connection
Expand Down
3 changes: 3 additions & 0 deletions extensions/lisp-mode/lem-lisp-mode.asd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
(:file "ext/test-runner")
(:file "ext/utopian")
(:file "ext/highlight")

(:file "read-only-sources")

(:file "package")))

(defsystem "lem-lisp-mode/v2"
Expand Down
14 changes: 14 additions & 0 deletions extensions/lisp-mode/read-only-sources.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(uiop:define-package :lem-lisp-mode/read-only-sources
(:use :cl)
(:import-from :lem/read-only-sources
:define-read-only-source))
(in-package :lem-lisp-mode/read-only-sources)

(define-read-only-source sbcl-source (directory)
(alexandria:when-let (connection (lem-lisp-mode/internal:current-connection))
(dolist (pattern (lem-lisp-mode/connection:connection-system-file-patterns connection))
(when (pathname-match-p directory pattern)
(return t)))))

(define-read-only-source quicklisp-dists (directory)
(search "/dists/quicklisp/software/" directory))
3 changes: 2 additions & 1 deletion lem.asd
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
(:file "filer")
(:file "deepl")
(:file "themes")
(:file "detective")))
(:file "detective")
(:file "read-only-sources")))

(:module "ui"
:serial t
Expand Down
29 changes: 29 additions & 0 deletions src/ext/read-only-sources.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(uiop:define-package :lem/read-only-sources
(:use :cl :lem)
(:export :read-only-sources
:define-read-only-source))
(in-package :lem/read-only-sources)

(define-editor-variable read-only-sources t)

(defvar *patterns* (make-hash-table :test 'equal))

(defun register-pattern (name function)
(setf (gethash name *patterns*) function))

(defmacro define-read-only-source (name (directory) &body body)
`(register-pattern ',name (lambda (,directory) ,@body)))

(defun read-only-source-p (directory)
(maphash (lambda (name pattern)
(declare (ignore name))
(when (funcall pattern directory)
(return-from read-only-source-p t)))
*patterns*))

(defun on-switch-to-buffer (buffer)
(when (and (variable-value 'read-only-sources :default buffer)
(read-only-source-p (buffer-directory buffer)))
(setf (buffer-read-only-p buffer) t)))

(add-hook *switch-to-buffer-hook* 'on-switch-to-buffer)

0 comments on commit 32a1d12

Please sign in to comment.