Skip to content

Commit

Permalink
Add apply-slot-setting function.
Browse files Browse the repository at this point in the history
Add `apply-slot-setting` function as a (bare-bones, first-iteration)
front-end for the setting package.
  • Loading branch information
hgluka committed Aug 28, 2023
1 parent 27c5916 commit b7d2515
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions source/help.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ Note that some settings may require restarting Nyxt to take effect.")
(:h2 "Miscellaneous")
(:ul
(:nbutton :text "Set default new buffer URL"
'(nyxt::configure-slot 'default-new-buffer-url 'browser :type 'string))
'(nyxt/setting:apply-slot-setting 'default-new-buffer-url 'nyxt/setting:browser-slot-setting))
(:nbutton :text "Set default zoom ratio"
'(nyxt::configure-slot 'zoom-ratio-default 'document-buffer))
'(nyxt/setting:apply-slot-setting 'zoom-ratio-default 'nyxt/setting:buffer-slot-setting))
(:p "On some systems, compositing can cause issues with rendering. If
you are experiencing blank web-views, you can try to disable compositing. After
disabling compositing, you will need to restart Nyxt.")
Expand Down
51 changes: 40 additions & 11 deletions source/setting.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ automatically filtered out. "
(funcall (all-instances setting))))
:key #'sera:class-name-of))))
(mapc (lambda (instance)
(alex:if-let ((writer (find-writer (target-class-name setting)
(slot-name setting))))
(funcall writer (new-value setting) instance)
(alex:if-let ((writer (find-writer (target-class-name setting)
(slot-name setting))))
(funcall writer (new-value setting) instance)
(setf (slot-value instance (slot-name setting)) (new-value setting))))
instances)))

Expand Down Expand Up @@ -238,15 +238,44 @@ automatically filtered out. "
(:export-accessor-names-p t)
(:documentation "A buffer setting is used for configuring buffers."))

(define-class keystyle (buffer-setting slot-setting)
((slot-name 'keyscheme))
(:documentation "A setting for configuring the keyscheme.
The new value is for example the 'nyxt/emacs-mode:emacs-mode' string."))
(define-class buffer-slot-setting (buffer-setting slot-setting)
((slot-name
nil
:type symbol)
(new-value
nil
:type t))
(:export-class-name-p t)
(:export-accessor-names-p t)
(:documentation "A setting for configuring a buffer slot."))

(define-class browser-slot-setting (browser-setting slot-setting)
((slot-name
nil
:type symbol)
(new-value
nil
:type t))
(:export-class-name-p t)
(:export-accessor-names-p t)
(:documentation "A setting for configuring a browser slot."))

(define-class zoom-ratio-default-setting (buffer-setting slot-setting)
((slot-name 'zoom-ratio-default))
(:documentation "A setting for configuring `zoom-ratio-default'.
The new value should be a float."))
(export-always 'apply-slot-setting)
(defun apply-slot-setting (slot-name slot-setting-class)
(let ((new-value (read-from-string
(prompt1
:prompt (format nil "Configure slot value ~a" slot-name)
:sources 'prompter:raw-source)))
(auto-config-p (if-confirm ("Apply this setting on restart?")))
(new-instances-p (if-confirm ("Apply this setting until the end of this session?")))
(all-instances-p (if-confirm ("Apply this setting immediately?"))))
(when (mopu:subclassp slot-setting-class 'slot-setting)
(apply-setting (make-instance slot-setting-class
:slot-name slot-name
:new-value new-value)
:auto-config-p auto-config-p
:new-instances-p new-instances-p
:all-instances-p all-instances-p))))

(defun find-setting (setting-designator)
(gethash (intern (symbol-name setting-designator))
Expand Down

0 comments on commit b7d2515

Please sign in to comment.