Clicking the current context now toggles zoom.
[lurk.git] / lurk.el
diff --git a/lurk.el b/lurk.el
index 66517ba..edfb66f 100644 (file)
--- a/lurk.el
+++ b/lurk.el
@@ -321,14 +321,13 @@ portion of the source component of the message, as LURK doesn't use this.")
 (defun lurk-set-current-context (context)
   (setq lurk-current-context context)
   (lurk-highlight-context context)
+  (lurk-render-prompt)
   (if lurk-zoomed
       (lurk-zoom-in lurk-current-context)))
 
 (defun lurk-cycle-contexts (&optional rev)
   (if lurk-current-context
-      (progn
-        (lurk-set-current-context (lurk-get-next-context rev))
-        (lurk-render-prompt))
+      (lurk-set-current-context (lurk-get-next-context rev))
     (lurk-display-error "No channels joined.")))
 
 
@@ -409,6 +408,11 @@ portion of the source component of the message, as LURK doesn't use this.")
     (if lurk-display-header
         (lurk-setup-header))))
 
+(defun lurk-clear-buffer ()
+  "Completely erase all non-prompt and non-input text from lurk buffer."
+  (with-current-buffer "*lurk*"
+    (let ((inhibit-read-only t))
+      (delete-region (point-min) lurk-prompt-marker))))
 
 ;;; Output formatting and highlighting
 ;;
@@ -459,6 +463,20 @@ portion of the source component of the message, as LURK doesn't use this.")
           (with-selected-window window
             (recenter -1))))))
 
+(defun lurk-make-context-button (context &optional label)
+  (with-temp-buffer
+    (insert-text-button (or label context)
+                        'action #'lurk--context-button-action
+                        'follow-link t
+                        'help-echo "Switch context.")
+    (buffer-string)))
+
+(defun lurk--context-button-action (button)
+  (let ((context (button-get button 'context)))
+    (if (eq lurk-current-context context)
+        (lurk-toggle-zoom)
+      (lurk-set-current-context context))))
+
 (defun lurk-display-string (context prefix &rest strings)
   (with-current-buffer "*lurk*"
     (save-excursion
@@ -498,8 +516,10 @@ portion of the source component of the message, as LURK doesn't use this.")
      context
      (propertize
       (pcase (lurk-get-context-type to)
-        ('channel (concat to " <" from ">"))
-        ('nick (concat "[" from " -> " to "]"))
+        ('channel (concat
+                   (lurk-make-context-button to)
+                   " <" from ">"))
+        ('nick (lurk-make-context-button context (concat "[" from " -> " to "]")))
         (_
          (error "Unsupported context type")))
       'face (lurk-get-context-facelist context))
@@ -512,7 +532,7 @@ portion of the source component of the message, as LURK doesn't use this.")
     (lurk-display-string
      context
      (propertize
-      (concat context " * " from)
+      (concat (lurk-make-context-button context) " * " from)
       'face (lurk-get-context-facelist context))
      action-text)))
 
@@ -560,6 +580,16 @@ portion of the source component of the message, as LURK doesn't use this.")
     (force-window-update "*lurk*"))
   (lurk-scroll-windows-to-last-line))
 
+(defun lurk-clear-context (context)
+  (with-current-buffer "*lurk*"
+    (save-excursion
+      (goto-char (point-min))
+      (let ((inhibit-read-only t)
+            (match nil))
+        (while (setq match (text-property-search-forward 'context context t))
+          (delete-region (prop-match-beginning match)
+                         (prop-match-end match)))))))
+
 (defconst lurk-url-regex
   (rx (:
        (group (+ alpha))
@@ -602,7 +632,8 @@ portion of the source component of the message, as LURK doesn't use this.")
           (strikethrough nil)
           (prev-point (point)))
       (while (re-search-forward (rx (or (any "\x02\x1D\x1F\x1E\x0F")
-                                        (: "\x03" (+ digit) (opt "," (* digit))))) nil t)
+                                        (: "\x03" (+ digit) (opt "," (* digit)))))
+                                nil t)
         (let ((beg (+ (match-beginning 0) 1)))
           (if bold
               (add-face-text-property prev-point beg '(:weight bold)))
@@ -860,6 +891,7 @@ in which case they match anything.")
     ("LIST" "Display details of one or more channels." lurk-command-list)
     ("WHOIS" "Ask server for details of nick." nil lurk-nick-completions)
     ("MSG" "Send private message to user." lurk-command-msg lurk-nick-completions)
+    ("CLEAR" "Clear buffer text." lurk-command-clear lurk-context-completions)
     ("HELP" "Display help on client commands." lurk-command-help lurk-help-completions))
   "Table of commands explicitly supported by Lurk.")
 
@@ -994,6 +1026,11 @@ in which case they match anything.")
         (lurk-display-message lurk-nick to text))
     (lurk-display-notice nil "Usage: /msg <nick> <message>")))
 
+(defun lurk-command-clear (params)
+  (if (not params)
+      (lurk-clear-buffer)
+    (dolist (context params)
+      (lurk-clear-context context))))
 
 ;;; Command entering
 ;;