From 04e0b9a5d0b400870e6ca39f454e7ed388ffe0af Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 27 Feb 2024 14:53:14 +0200 Subject: nyxt: Rewrite modules --- .config/nyxt/commands.lisp | 63 ---------------------------------------- .config/nyxt/default-search.lisp | 17 +++++++++++ .config/nyxt/handle-url.lisp | 63 ++++++++++++++++++++++++++++++++++++++++ .config/nyxt/style.lisp | 4 +-- 4 files changed, 82 insertions(+), 65 deletions(-) delete mode 100644 .config/nyxt/commands.lisp create mode 100644 .config/nyxt/default-search.lisp create mode 100644 .config/nyxt/handle-url.lisp (limited to '.config/nyxt') diff --git a/.config/nyxt/commands.lisp b/.config/nyxt/commands.lisp deleted file mode 100644 index 1739793..0000000 --- a/.config/nyxt/commands.lisp +++ /dev/null @@ -1,63 +0,0 @@ -(in-package #:nyxt-user) - -(defvar *thanos/search-engines* - (list - '("google" "https://google.com/search?q=~a") - '("aa" "https://annas-archive.org/search?q=~a") - '("v" "https://yewtu.be/search?q=~a") - '("aw" "https://wiki.archlinux.org/index.php?search=~a") - '("duck" "https://duckduckgo.com/?q=~a")) - "List of search engines. -Last entry is the default.") - -(defun direct-url-p (url) - "Checks if `url` is a direct URL with specific extensions, returning -t if so and nil otherwise. The URL must not contain spaces." - (not (null (or (and (null (cl-ppcre:scan "\\s" url)) - (or (cl-ppcre:scan "^(https?://)?.*\\.org(\\/.*)?$" url) - (cl-ppcre:scan "^(https?://)?.*\\.com(\\/.*)?$" url) - (cl-ppcre:scan "^(https?://)?.*\\.net(\\/.*)?$" url) - (cl-ppcre:scan "^(https?://)?.*\\.gr(\\/.*)?$" url) - (cl-ppcre:scan "^(https?://)?.*\\.co(\\/.*)?$" url) - (cl-ppcre:scan "^(https?://)?.*\\.engineer(\\/.*)?$" url))))))) - -(defun handle-url (query func) - "Process `query` as a URL or search query. - -Applies `func` to the query`. -Requires the variable `*thanos/search-engines*` for search queries." - (cond - ((or (str:starts-with-p "localhost" query)) - (funcall func (str:concat "http://" query))) - ((direct-url-p query) - (funcall func (str:concat "https://" query))) - ((str:starts-with-p "http" query) - (funcall func query)) - ((let ((split-result (str:split #\Space query))) - (find (first split-result) *thanos/search-engines* :key #'first :test #'string=)) - (let* ((engine-tag (subseq query 0 (position #\Space query))) - (query (subseq query (+ 1 (position #\Space query)))) - (engine (find engine-tag *thanos/search-engines* :key #'first :test #'string=)) - (search-url (second engine))) - (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query))))) - (t - (let* ((engine (first (last *thanos/search-engines*))) - (search-url (second engine))) - (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query))))))) - -(defun thanos/make-buffer-focus-url (url) - (make-buffer-focus :url url)) - -(define-command-global thanos/set-url () - (let* ((prompt-result (first - (prompt - :prompt "Search" - :sources (list (make-instance 'prompter:raw-source)))))) - (handle-url prompt-result 'buffer-load))) - -(define-command-global thanos/set-url-new-buffer () - (let* ((prompt-result (first - (prompt - :prompt "Search [New Buffer]" - :sources (list (make-instance 'prompter:raw-source)))))) - (handle-url prompt-result 'thanos/make-buffer-focus-url))) diff --git a/.config/nyxt/default-search.lisp b/.config/nyxt/default-search.lisp new file mode 100644 index 0000000..9d47fc7 --- /dev/null +++ b/.config/nyxt/default-search.lisp @@ -0,0 +1,17 @@ + +(defvar *my-search-engines* + (list + '("google" "https://google.com/search?q=~a" "https://google.com") + '("doi" "https://dx.doi.org/~a" "https://dx.doi.org/") + '("python3" "https://docs.python.org/3/search.html?q=~a" + "https://docs.python.org/3") + '("duck" "https://duckduckgo.com/?q=~a" "https://duckduckgo.com/")) + "List of search engines.") + +(define-configuration context-buffer + "Go through the search engines above and make-search-engine out of them." + ((search-engines + (append %slot-default% + (mapcar + (lambda (engine) (apply 'make-search-engine engine)) + *my-search-engines*))))) diff --git a/.config/nyxt/handle-url.lisp b/.config/nyxt/handle-url.lisp new file mode 100644 index 0000000..1739793 --- /dev/null +++ b/.config/nyxt/handle-url.lisp @@ -0,0 +1,63 @@ +(in-package #:nyxt-user) + +(defvar *thanos/search-engines* + (list + '("google" "https://google.com/search?q=~a") + '("aa" "https://annas-archive.org/search?q=~a") + '("v" "https://yewtu.be/search?q=~a") + '("aw" "https://wiki.archlinux.org/index.php?search=~a") + '("duck" "https://duckduckgo.com/?q=~a")) + "List of search engines. +Last entry is the default.") + +(defun direct-url-p (url) + "Checks if `url` is a direct URL with specific extensions, returning +t if so and nil otherwise. The URL must not contain spaces." + (not (null (or (and (null (cl-ppcre:scan "\\s" url)) + (or (cl-ppcre:scan "^(https?://)?.*\\.org(\\/.*)?$" url) + (cl-ppcre:scan "^(https?://)?.*\\.com(\\/.*)?$" url) + (cl-ppcre:scan "^(https?://)?.*\\.net(\\/.*)?$" url) + (cl-ppcre:scan "^(https?://)?.*\\.gr(\\/.*)?$" url) + (cl-ppcre:scan "^(https?://)?.*\\.co(\\/.*)?$" url) + (cl-ppcre:scan "^(https?://)?.*\\.engineer(\\/.*)?$" url))))))) + +(defun handle-url (query func) + "Process `query` as a URL or search query. + +Applies `func` to the query`. +Requires the variable `*thanos/search-engines*` for search queries." + (cond + ((or (str:starts-with-p "localhost" query)) + (funcall func (str:concat "http://" query))) + ((direct-url-p query) + (funcall func (str:concat "https://" query))) + ((str:starts-with-p "http" query) + (funcall func query)) + ((let ((split-result (str:split #\Space query))) + (find (first split-result) *thanos/search-engines* :key #'first :test #'string=)) + (let* ((engine-tag (subseq query 0 (position #\Space query))) + (query (subseq query (+ 1 (position #\Space query)))) + (engine (find engine-tag *thanos/search-engines* :key #'first :test #'string=)) + (search-url (second engine))) + (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query))))) + (t + (let* ((engine (first (last *thanos/search-engines*))) + (search-url (second engine))) + (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query))))))) + +(defun thanos/make-buffer-focus-url (url) + (make-buffer-focus :url url)) + +(define-command-global thanos/set-url () + (let* ((prompt-result (first + (prompt + :prompt "Search" + :sources (list (make-instance 'prompter:raw-source)))))) + (handle-url prompt-result 'buffer-load))) + +(define-command-global thanos/set-url-new-buffer () + (let* ((prompt-result (first + (prompt + :prompt "Search [New Buffer]" + :sources (list (make-instance 'prompter:raw-source)))))) + (handle-url prompt-result 'thanos/make-buffer-focus-url))) diff --git a/.config/nyxt/style.lisp b/.config/nyxt/style.lisp index 4dee682..c1b1304 100644 --- a/.config/nyxt/style.lisp +++ b/.config/nyxt/style.lisp @@ -135,9 +135,9 @@ automatically, which should be good enough... for most cases."))) :background-image none "!important" :color ,badger-blue "!important") `(* :background-color "#000000" "!important" + :background-image none "!important" :color "#ffffff" "!important" - :background-image none "!important!") - `(video :background-color none "!important")))) + :background-image none "!important!")))) :doc "Notice the use of theme:themed-css for convenient theme color injection.") -- cgit v1.2.3