Skip to content

Commit

Permalink
Delete auto-rules.
Browse files Browse the repository at this point in the history
Closes #3600.
  • Loading branch information
aadcg committed Feb 17, 2025
1 parent 839ca92 commit 607d7af
Show file tree
Hide file tree
Showing 27 changed files with 22 additions and 647 deletions.
1 change: 0 additions & 1 deletion nyxt.asd
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
(:file "window")
(:file "mode")
(:file "history")
(:file "auto-rules")
(:file "spinneret-tags")
(:file "browser")
(:file "foreign-interface")
Expand Down
493 changes: 0 additions & 493 deletions source/auto-rules.lisp

This file was deleted.

48 changes: 0 additions & 48 deletions source/buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -335,54 +335,6 @@ Useful in FFI functions where we usually specialize things against
Modes are instantiated over the result of the `default-modes' method, with
`finalize-buffer' and not in the initform so that the instantiation form can
access the initialized buffer.")
(auto-rules-file
(make-instance 'auto-rules-file)
:type auto-rules-file
:documentation "File where the auto-rules are saved.")
(apply-all-matching-auto-rules-p
nil
:type boolean
:documentation "Whether all matching auto-rules are applied to the URL.
If nil, the most specific rule is applied.")
(prompt-on-mode-toggle-p
nil
:type boolean
:documentation "Whether the user is prompted to confirm adding the auto-rule
on mode toggling.")
(previous-url
nil
:export nil
:type (or quri:uri null)
:documentation "The last URL for which auto-rules were applied.
We need to know if the auto-rule has been applied before to avoid re-applying a
rule for a sequence of pages that match the same rule.
We can't rely on the previous history entry because dead buffers and
session-restored buffers may have a history with a previous URL matching the
same rule while obviously the rule has never been applied for the new-born
buffer.")
(last-active-modes-url
nil
:export nil
:type (or quri:uri null)
:documentation "The last URL for which the active modes were saved.
We need to store this to not overwrite the `last-active-modes' for a given URL
if it's being reloaded.")
(last-active-modes
'()
:export nil
:type (or (cons mode-invocation *) null)
:documentation "The list of `mode-invocation's that were enabled on the last
URL not covered by auto-rules.
This is useful when alternating between URLs for which auto-rules are enabled or
disabled. Example browsing sequence:
- https://example.org (no-script-mode no-image-mode) ; No rule.
- https://nyxt-browser.com (dark-mode) ; Rule
- https://en.wikipedia.org (no-script-mode no-image-mode) ; No rule.
When browsing from nyxt-browser.com to en.wikipedia.org, the modes that were
enabled before nyxt-browser.com are restored.")
(enable-mode-hook
(make-instance 'hook-mode)
:type hook-mode
Expand Down
38 changes: 0 additions & 38 deletions source/manual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ of Nyxt.")
(spinneret:with-html-string
(let ((auto-config-file (namestring (files:expand *auto-config-file*)))
(config-file (namestring (files:expand *config-file*)))
(rules-file (namestring (files:expand (make-instance 'auto-rules-file))))
(gtk-extensions-directory (namestring (uiop:merge-pathnames* "nyxt/" nasdf:*libdir*))))
(:nsection :title "Configuration"
(:p "Nyxt is written in the Common Lisp programming language which offers a
Expand Down Expand Up @@ -252,43 +251,6 @@ loaded. For instance, you can configure which Torrent program to start to load
magnet links. See the " (:nxref :function 'url-dispatching-handler) " function
documentation."))

(:nsection :title "Auto rules"
(:p "Auto-rules toggle modes when the URL satisfies the given
conditions. URL-dispatchers can also be used for this, but it is
simpler to use an auto-rule. Given that Nyxt's functionality is
mode-based, the consequences are far reaching.")
(:p "These can be used in the following ways:")
(:ul
(:li "Manually, by calling:")
(:dl
(:dt (:nxref :command 'save-non-default-modes-for-future-visits))
(:dd "which saves \"unusual\" modes - non-default modes that were
toggled exclusively for a given URL.")
(:dt (:nxref :command 'save-exact-modes-for-future-visits))
(:dd "which saves the exact list of enabled modes for a given
URL."))
(:li "Automatically, by setting "
(:nxref :slot 'prompt-on-mode-toggle-p :class-name 'modable-buffer)
" to non-nil (refer to the "
(:a :href "#configuration" "configuration section") " for help)."))
(:p "All rules are stored at " (:code rules-file) ", which " (:u "is
meant to be human-readable and human-writable")". You can find instructions at the top of it.
The gist is that rules are mere Lisp lists which start with a condition that checks the
URL. When conditions are met, modes are toggled. Besides user-defined conditions, the
following are often useful: "
(:ul
(:li (:nxref :function 'match-domain))
(:li (:nxref :function 'match-host))
(:li (:nxref :function 'match-url))
(:li (:nxref :function 'match-regex))
(:li (:nxref :function 'match-scheme))))
(:p "By default, "
(:nxref :slot 'apply-all-matching-auto-rules-p :class-name 'modable-buffer)
" is nil meaning that only the most specific rules are honored.")
(:p "Auto-rules can also be defined for custom use-cases via "
(:nxref :function 'define-auto-rule) " and un-defined with "
(:nxref :function 'undefine-auto-rule) "."))

(:nsection
:title "Custom commands"
:open-p nil
Expand Down
23 changes: 7 additions & 16 deletions source/mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ Only used to mandate whether the mode needs a toggler command:
:accessor nil
:documentation "A `status-buffer' indicator that mode is enabled, when
`glyph-mode-presentation-p' is non-nil.")
(rememberable-p
t
:documentation "Whether this mode is visible to auto-rules.")
(enabled-p
nil
:accessor t
Expand Down Expand Up @@ -386,7 +383,7 @@ For production code, see `find-submode' instead."
(:documentation "Source listing names of modes not yet `enable'd (or `disable'd) in `buffers'."))

(export-always 'enable-modes*)
(defgeneric enable-modes* (modes buffers &rest args &key remember-p &allow-other-keys)
(defgeneric enable-modes* (modes buffers &rest args &key &allow-other-keys)
;; FIXME: Better type dispatching? The types used to be:
;; (-> enable-modes* ((or sym:mode-symbol (list-of sym:mode-symbol))
;; (or buffer (list-of buffer))
Expand All @@ -408,8 +405,7 @@ For production code, see `find-submode' instead."
buffer)
(sera:filter #'modable-buffer-p buffers))))
(:documentation "Enable MODES in BUFFERS.
ARGS are the keyword arguments for `make-instance'/`enable' on MODES.
If REMEMBER-P is true, save active modes so that auto-rules don't override those."))
ARGS are the keyword arguments for `make-instance'/`enable' on MODES."))

(define-command enable-modes (&key
(modes nil modes-supplied-p)
Expand All @@ -436,12 +432,11 @@ If it's a single buffer, return it directly (not as a list)."
:prompt "Enable mode(s)"
:sources (make-instance 'inactive-mode-source
:buffers buffers))))))
(enable-modes* modes buffers)
(remember-on-mode-toggle modes buffers :enabled-p t))
(enable-modes* modes buffers))
buffers)

(export-always 'disable-modes*)
(defgeneric disable-modes* (modes buffers &rest args &key remember-p &allow-other-keys)
(defgeneric disable-modes* (modes buffers &rest args &key &allow-other-keys)
;; FIXME: Better type dispatching?
(:method (modes buffers &rest args &key &allow-other-keys)
(declare (ignorable args))
Expand All @@ -456,8 +451,7 @@ If it's a single buffer, return it directly (not as a list)."
(delete nil (mapcar (lambda (mode) (find mode (modes buffer) :key #'name))
modes))))
buffers)))
(:documentation "Disable MODES in BUFFERS.
If REMEMBER-P is true, save active modes so that auto-rules don't override those."))
(:documentation "Disable MODES in BUFFERS."))

(define-command disable-modes (&key (modes nil modes-supplied-p)
(buffers (current-buffer) buffers-supplied-p))
Expand All @@ -480,8 +474,7 @@ If it's a single buffer, return it directly (not as a list)."
:prompt "Disable mode(s)"
:sources (make-instance 'active-mode-source
:buffers buffers))))))
(disable-modes* modes buffers)
(remember-on-mode-toggle modes buffers :enabled-p nil))
(disable-modes* modes buffers))
buffers)

(define-command toggle-modes (&key (buffer (current-buffer)))
Expand All @@ -495,9 +488,7 @@ If it's a single buffer, return it directly (not as a list)."
(modes-to-disable (set-difference (all-mode-symbols) modes-to-enable
:test #'string=)))
(disable-modes* modes-to-disable buffer)
(remember-on-mode-toggle modes-to-disable buffer :enabled-p nil)
(enable-modes* modes-to-enable buffer)
(remember-on-mode-toggle modes-to-enable buffer :enabled-p t))
(enable-modes* modes-to-enable buffer))
buffer)

;; TODO: Factor `toggle-mode' and `toggle-modes' somehow?
Expand Down
1 change: 0 additions & 1 deletion source/mode/autofill.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ See the `autofill-mode' for the external user-facing APIs."))
See `nyxt/mode/autofill' package documentation for implementation details and
internal programming APIs."
((visible-in-status-p nil)
(rememberable-p t)
(autofills
(list (make-autofill :name "Name" :fill "My Name")
(make-autofill :name "Hello Printer"
Expand Down
1 change: 0 additions & 1 deletion source/mode/base.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"Bind general-purpose commands defined by `define-command'.
This mode is a good candidate to be passed to `make-buffer'."
((visible-in-status-p nil)
(rememberable-p nil)
(keyscheme-map
(define-keyscheme-map "base-mode" ()
keyscheme:default
Expand Down
3 changes: 1 addition & 2 deletions source/mode/cruise-control.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ The main API point is `cruise-control-mode'."))
(define-mode cruise-control-mode (nyxt/mode/repeat:repeat-mode)
"Mode for automatically scrolling up and down the page.
It inherits from `nyxt/mode/repeat:repeat-mode'."
((rememberable-p t)
(velocity
((velocity
0
:documentation "The distance the page is scrolling on each update interval.
A positive velocity corresponds to scrolling down, a negative velocity
Expand Down
1 change: 0 additions & 1 deletion source/mode/document.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Important pieces of functionality are:
- Heading navigation.
- Frame selection."
((visible-in-status-p nil)
(rememberable-p nil)
(keyscheme-map
(define-keyscheme-map "document-mode" ()
keyscheme:default
Expand Down
4 changes: 1 addition & 3 deletions source/mode/expedition.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
keyscheme:emacs
(list
"M-p" 'expedition-previous
"M-n" 'expedition-next)))
(rememberable-p nil)))
"M-n" 'expedition-next)))))

(define-command expedition-next (&key (expedition (find-submode 'expedition-mode)))
"Go to the next URL in the expedition."
Expand Down Expand Up @@ -52,5 +51,4 @@
(urls (mapcar #'quri:uri urls))
(buffer (make-buffer :title "" :url (first urls))))
(enable (make-instance 'expedition-mode :urls urls :buffer buffer))
(nyxt::remember-on-mode-toggle (list 'expedition-mode) buffer :enabled-p t)
(set-current-buffer buffer)))
8 changes: 2 additions & 6 deletions source/mode/force-https.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ help on how to proceed."
(:code "force-https-mode") " is on.")
(:p "Since HTTP connections are not secure,"
" it's not recommended to proceed if you don't trust the target host.")
(:p " If you really want to proceed, you can either:"
(:ul
(:li "disable "
(:code "force-https-mode") " temporarily;")
(:li "or disable it dynamically with auto-rules' "
(:code "save-exact-modes-for-future-visits") "."))))
(:p " If you really want to proceed, you can disable " (:code "force-https-mode")
" temporarily."))
buffer))

(define-mode force-https-mode ()
Expand Down
1 change: 0 additions & 1 deletion source/mode/hint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Exposes the APIs below:
(define-mode hint-mode ()
"Interact with elements by typing a short character sequence."
((visible-in-status-p nil)
(rememberable-p nil)
(hinting-type
:emacs
:type (member :emacs :vi)
Expand Down
3 changes: 1 addition & 2 deletions source/mode/history-migration.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ browsers."))

(define-mode history-migration-mode ()
"Mode for importing history from other browsers."
((visible-in-status-p nil)
(rememberable-p nil))
((visible-in-status-p nil))
(:toggler-command-p nil))

(define-class external-browser-history-source (prompter:source)
Expand Down
1 change: 0 additions & 1 deletion source/mode/input-edit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ Run the BODY in the environment with these bound."
Overrides many of the bindings in other modes, so you will have to
disable/enable it as necessary."
((visible-in-status-p nil)
(rememberable-p nil)
(keyscheme-map
(define-keyscheme-map "input-edit-mode" ()
;; TODO: Add VI-normal?
Expand Down
3 changes: 1 addition & 2 deletions source/mode/keyscheme.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Example of defining a keyscheme mode:
(define-mode my-keyscheme-mode (nyxt/mode/keyscheme:keyscheme-mode)
((keyscheme keyscheme:my-keyscheme-mode)))"
((rememberable-p nil)
(keyscheme ; This specialized `nyxt:keyscheme'.
((keyscheme ; This specialized `nyxt:keyscheme'.
keyscheme:cua
:documentation "The `keymaps:keyscheme' to enable.")
(previous-keyscheme
Expand Down
1 change: 0 additions & 1 deletion source/mode/process.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extended with custom logic.
See `nyxt/mode/process' package documentation for implementation details and internal programming APIs."
((visible-in-status-p nil)
(rememberable-p nil)
(path-url
nil
:type (or quri:uri null)
Expand Down
3 changes: 1 addition & 2 deletions source/mode/reading-line.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Commands:
- `jump-to-reading-line-cursor': If you navigate away from the reading line, you
can always invoke this command to jump back to your reading position."
((rememberable-p nil)
(visible-in-status-p nil)
((visible-in-status-p nil)
(keyscheme-map
(define-keyscheme-map "reading-line-mode" ()
keyscheme:cua
Expand Down
1 change: 0 additions & 1 deletion source/mode/repeat.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ The commands that `repeat-mode' exposes are:
See `nyxt/mode/repeat' package documentation for implementation details and
internal programming APIs."
((visible-in-status-p nil)
(rememberable-p nil)
(repeat-count
nil
:type (or integer null)
Expand Down
1 change: 0 additions & 1 deletion source/mode/search-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
(define-mode search-buffer-mode ()
"Incremental search on a single or multiple buffers."
((visible-in-status-p nil)
(rememberable-p nil)
(style
(theme:themed-css (theme *browser*)
`("span[nyxt-search-mark]"
Expand Down
5 changes: 2 additions & 3 deletions source/mode/small-web.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Implies that `small-web-mode' is enabled."))
(let ((line (if (uiop:emptyp (quri:uri-path (quri:uri url)))
(buffer-load (str:concat url "/"))
(cl-gopher:parse-gopher-uri url))))
(enable-modes :modes '(small-web-mode))
(if (and (typep line 'cl-gopher:search-line)
(uiop:emptyp (cl-gopher:terms line)))
(progn (setf (cl-gopher:terms line)
Expand Down Expand Up @@ -279,6 +280,7 @@ Implies that `small-web-mode' is enabled."
(lambda (url)
(handler-case
(sera:mvlet* ((status meta body (gemini:request url)))
(enable-modes :modes '(small-web-mode))
(unless (member status '(:redirect :permanent-redirect))
(setf (nyxt/mode/small-web:redirections (find-submode 'small-web-mode)) nil))
(case status
Expand Down Expand Up @@ -323,6 +325,3 @@ Implies that `small-web-mode' is enabled."
(condition (condition)
(error-help "Unknown error"
(format nil "Original text of ~a:~%~a" (type-of condition) condition))))))

(define-auto-rule '(match-scheme "gopher" "gemini")
:included '(small-web-mode))
1 change: 0 additions & 1 deletion source/mode/spell-check.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ It leverages `enchant' under the hood."))
(define-mode spell-check-mode ()
"Enable spell checking of various text sources."
((visible-in-status-p nil)
(rememberable-p t)
(spell-check-language
"en_US"
:documentation "Spell check language used by Nyxt.
Expand Down
3 changes: 1 addition & 2 deletions source/mode/user-script.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ If false, runs on the toplevel frame only.")
"Mode to manage user scripts such as GreaseMonkey scripts.
The mode can manage multiple scripts. Each `user-script' behaves following to
its own independent settings."
((rememberable-p nil)
(user-scripts
((user-scripts
nil
:reader user-scripts
:type (list-of user-script)
Expand Down
3 changes: 1 addition & 2 deletions source/mode/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

(define-mode visual-mode (nyxt/mode/hint:hint-mode)
"Browse the page with a cursor to select text."
((rememberable-p nil)
(nyxt/mode/hint:hints-selector
((nyxt/mode/hint:hints-selector
"a, b, p, del, h1, h2, h3, h4, h5, h6, i, option, strong, sub, sup, listing,
xmp, plaintext, basefont, big, blink, center, font, marquee, multicol, nobr, s,
spacer, strike, tt, u, wbr, code, cite, pre"
Expand Down
5 changes: 2 additions & 3 deletions source/mode/watch.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

(define-mode watch-mode (nyxt/mode/repeat:repeat-mode)
"Reload the current buffer every 5 minutes."
((rememberable-p t)
(nyxt/mode/repeat:repeat-interval 300.0)
((nyxt/mode/repeat:repeat-interval 300.0)
(nyxt/mode/repeat:repeat-action
#'(lambda (mode)
(ffi-buffer-reload (buffer mode)))
Expand All @@ -43,4 +42,4 @@
(define-command-global watch-buffer (&optional (buffer (current-buffer)))
"Reload BUFFER at a prompted interval."
(let ((interval (seconds-from-user-input)))
(enable-modes* 'watch-mode buffer :repeat-interval interval :remember-p t)))
(enable-modes* 'watch-mode buffer :repeat-interval interval)))
Loading

0 comments on commit 607d7af

Please sign in to comment.