-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add impl-source-read-only editor-variable #1656
Conversation
Still i don't know how to send the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR.
This suggestion for improvement is wonderful.
I am also grateful that you actually made the suggestion into a PR.
Also, I have some comments and suggestions regarding the changes.
Thank you.
suggestion 1
What about separating the files?
I think it can be separated into a single function: make this particular directory read-only.
Then it seems to me that it would be better to separate each file/package.
;; src/ext/read-only-sources.lisp
(uiop:define-package :lem/read-only-sources
(:use :cl :lem)
...)
(in-package :lem/read-only-sources)
...
(add-hook *switch-to-buffer-hook* 'on-switch-to-buffer)
suggestion 2
How about separating the definition of the rules for making it read-only from the hooks?
For example, the following macro defines a rule.
;; lisp-mode.lisp
(define-read-only-source sbcl-source (directory)
(dolist (pattern (connection-system-file-patterns (current-connection)))
(when (pathname-match-p directory pattern)
(return t))))
The definition of this macro is placed in the same place as the hook.
;; src/ext/read-only-sources.lisp
(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)
The Suggestion 1 would be good, to extract the feature into an extension, reducing the complexity of the core source. The Suggestion 2 makes the read-only a facility to support other purpose, looks nice. You can close this issue, if you have implement the source in your side. |
OK. Please let me know if there are any deficiencies. |
To close issue: #1615
This option is enabled by default, to disable it, eval the form in
init.lisp
The typical value of source dir for
sbcl implementation
are:/usr/share/sbcl-source/src/code/
(installed viayay -S sbcl
)~/.roswell/src/sbcl-2.4.10/src/code/
(installed viaroswell
)There may be a better function to decide if
(current-directory)
is part ofimplementation source directory
.