- (let* ((pos lurk-prompt-marker)
- (nextpos (previous-single-property-change pos 'context))
- (inhibit-read-only t))
- (while (> pos nextpos)
- (let ((thiscontext (get-text-property nextpos 'context)))
- (if thiscontext
- (if (equal context thiscontext)
- (add-text-properties nextpos pos
- '(face (foreground-color . "green")))
- (add-text-properties nextpos pos
- '(face (foreground-color . "blue"))))
- (add-text-properties nextpos pos
- '(face lurk-text)))
- thiscontext
- (setq pos nextpos)
- (setq nextpos (previous-single-property-change pos 'context nil 1)))))))
+ (maphash
+ (lambda (this-context _)
+ (when this-context
+ (let ((this-context-atom (intern this-context)))
+ (if (equal this-context context)
+ (remove-from-invisibility-spec this-context-atom)
+ (add-to-invisibility-spec this-context-atom)))))
+ lurk-context-facelists)
+ (force-window-update "*lurk*")))
+
+(defun lurk-zoom-out ()
+ (with-current-buffer "*lurk*"
+ (maphash
+ (lambda (this-context _)
+ (let ((this-context-atom (if this-context (intern this-context) nil)))
+ (remove-from-invisibility-spec this-context-atom)))
+ lurk-context-facelists)
+ (force-window-update "*lurk*")))
+
+(defconst lurk-url-regex
+ (rx (:
+ (group (+ alpha))
+ "://"
+ (group (or (+ (any alnum "." "-"))
+ (+ (any alnum ":"))))
+ (opt (group (: ":" (+ digit))))
+ (opt (group (: "/"
+ (opt
+ (* (any alnum "-/.,#:%=&_"))
+ (any alnum "-/#:%=&_")))))))
+ "Imperfect regex used to find URLs in plain text.")
+
+(defun lurk-click-url (button)
+ (browse-url (button-get button 'url)))
+
+(defun lurk-buttonify-urls (string)
+ "Turn substrings which look like urls in STRING into clickable buttons."
+ (with-temp-buffer
+ (insert string)
+ (goto-char (point-min))
+ (while (re-search-forward lurk-url-regex nil t)
+ (let ((url (match-string 0)))
+ (make-text-button (match-beginning 0)
+ (match-end 0)
+ 'action #'lurk-click-url
+ 'url url
+ 'follow-link t
+ 'face 'button
+ 'help-echo "Open URL in browser.")))
+ (buffer-string)))
+