1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2025-03-12 11:20:05 +01:00

- [gemini] added 'search-message-gemini-fragment-event'

When  a fragment  is present  in a  uri/iri it  is used  as a  regular
expression to search in the *source* of the text, the window's content
is moved to shows the *rendered* line where matching occurred.
This commit is contained in:
cage 2021-11-06 12:32:03 +01:00
parent 5bbd5100c8
commit c3492c06c1
5 changed files with 20 additions and 16 deletions

View File

@ -210,7 +210,4 @@ open ".gpub$" with "tinmop"
# E.g. gemini://foo/bar.gmi#baz will jump to the first occurence of "baz" # E.g. gemini://foo/bar.gmi#baz will jump to the first occurence of "baz"
# the fragment is used as a regular expressions # the fragment is used as a regular expressions
# Note: incomplete implementation, works fine for headers, preformatted text,
# and likely links, broken for the rest.
experimental.gemini.iri.fragment.regex = no experimental.gemini.iri.fragment.regex = no

View File

@ -442,12 +442,14 @@
(setf (stream-status wrapper-object) :completed) (setf (stream-status wrapper-object) :completed)
(when (and fragment (when (and fragment
(swconf:config-gemini-fragment-as-regex-p)) (swconf:config-gemini-fragment-as-regex-p))
(let ((regex (if (text-utils:percent-encoded-p fragment) (let* ((regex (if (text-utils:percent-encoded-p fragment)
(text-utils:percent-encode fragment) (text-utils:percent-decode fragment)
fragment)) fragment))
(priority program-events:+standard-event-priority+)) (priority program-events:+standard-event-priority+)
(ui::message-search-regex-callback regex (event (make-instance 'program-events:search-message-gemini-fragment-event
:priority priority))))) :priority priority
:payload regex)))
(program-events:push-event event)))))
;; (allow-downloading wrapper-object) ;; (allow-downloading wrapper-object)
(gemini-client:close-ssl-socket download-socket)))))))) (gemini-client:close-ssl-socket download-socket))))))))
;; (fs:delete-file-if-exists support-file))))) ;; (fs:delete-file-if-exists support-file)))))
@ -727,10 +729,7 @@
:as-error t)) :as-error t))
#-debug-mode #-debug-mode
(error (e) (error (e)
(ui:notify (format nil (ui:notify (format nil (_ "Error getting ~s: ~a") url e)
(_ "Error getting ~s: ~a")
url
e)
:as-error t))))) :as-error t)))))
(defun history-back (window) (defun history-back (window)

View File

@ -741,7 +741,7 @@ fragment matches- move the window to the line when matching occurred."
finally (setf rest-blanks (subseq blanks ct))) finally (setf rest-blanks (subseq blanks ct)))
(values (reverse res) rest-blanks)))) (values (reverse res) rest-blanks))))
(with-accessors ((row-selected-index row-selected-index)) window (with-accessors ((row-selected-index row-selected-index)) window
(let ((rest-rows (rows-safe-subseq window row-selected-index)) (let ((rest-rows (rest (rows-safe-subseq window row-selected-index)))
(matching-source-line nil) (matching-source-line nil)
(matching-source-id nil) (matching-source-id nil)
(matching-source-position nil) (matching-source-position nil)
@ -772,7 +772,7 @@ fragment matches- move the window to the line when matching occurred."
(reconstructed-rows (reconstruct-source-lines text-rows matching-source-blanks)) (reconstructed-rows (reconstruct-source-lines text-rows matching-source-blanks))
(line-matched (loop (line-matched (loop
for reconstructed-row in reconstructed-rows for reconstructed-row in reconstructed-rows
for line from 0 for line from 1
for length-accum = (length reconstructed-row) for length-accum = (length reconstructed-row)
then (+ length-accum then (+ length-accum
(length reconstructed-row)) (length reconstructed-row))

View File

@ -1429,6 +1429,7 @@
:fetch-remote-status-event :fetch-remote-status-event
:process-event :process-event
:search-next-event :search-next-event
:search-message-gemini-fragment-event
:search-regex-message-content-event :search-regex-message-content-event
:thread-search-message-body-event :thread-search-message-body-event
:search-direction :search-direction
@ -2118,7 +2119,8 @@
:generate-gemini-toc :generate-gemini-toc
:gemini-toc-entry :gemini-toc-entry
:gemini-toc-group-id :gemini-toc-group-id
:init)) :init
:search-gemini-fragment))
(defpackage :open-attach-window (defpackage :open-attach-window
(:use (:use

View File

@ -453,6 +453,12 @@
(cl-ppcre:ppcre-syntax-error () (cl-ppcre:ppcre-syntax-error ()
(ui:error-message (_ "Invalid regular expression"))))))) (ui:error-message (_ "Invalid regular expression")))))))
(defclass search-message-gemini-fragment-event (search-event) ())
(defmethod process-event ((object search-message-gemini-fragment-event))
(let ((fragment (payload object)))
(message-window:search-gemini-fragment specials:*message-window* fragment)))
(defclass thread-search-event (search-event) (defclass thread-search-event (search-event)
((search-direction ((search-direction
:initform nil :initform nil