/nick command bugfix
[lurk.git] / lurk.el
diff --git a/lurk.el b/lurk.el
index 447f5f5..52ee3b6 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.")))
 
 
@@ -464,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
@@ -503,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))
@@ -517,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)))
 
@@ -875,6 +890,7 @@ in which case they match anything.")
     ("NICK" "Change nick." lurk-command-nick)
     ("LIST" "Display details of one or more channels." lurk-command-list)
     ("WHOIS" "Ask server for details of nick." nil lurk-nick-completions)
+    ("USERS" "List nicks of users in current context." lurk-command-users)
     ("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))
@@ -974,8 +990,8 @@ in which case they match anything.")
     (if new-nick
         (if (lurk-connected-p)
             (lurk-send-msg (lurk-msg nil nil "NICK" new-nick))
-          (setq lurk-nick nick)
-          (lurk-display-notice nil "Set default nick to '" nick "'."))
+          (setq lurk-nick new-nick)
+          (lurk-display-notice nil "Set default nick to '" lurk-nick "'."))
       (lurk-display-notice nil "Current nick: " lurk-nick))))
 
 (defun lurk-command-me (params)
@@ -1017,6 +1033,15 @@ in which case they match anything.")
     (dolist (context params)
       (lurk-clear-context context))))
 
+(defun lurk-command-users (params)
+  (if lurk-current-context
+      (progn
+        (lurk-display-notice lurk-current-context "Users in " lurk-current-context ":")
+        (lurk-display-notice
+         lurk-current-context
+         (string-join (lurk-get-context-users lurk-current-context) " ")))
+    (lurk-display-notice nil "No current channel.")))
+
 ;;; Command entering
 ;;
 
@@ -1099,7 +1124,7 @@ in which case they match anything.")
 (defun lurk-complete-input ()
   (interactive)
   (let ((completion-ignore-case t))
-    (when (and (>= (point) lurk-input-marker))
+    (when (>= (point) lurk-input-marker)
       (pcase (buffer-substring lurk-input-marker (point))
         ((rx (: "/" (let cmd-str (+ (not whitespace))) (+ " ") (* (not whitespace)) string-end))
          (let ((space-idx (save-excursion
@@ -1120,7 +1145,11 @@ in which case they match anything.")
                              (re-search-backward " " lurk-input-marker t)))
                 (start (if space-idx (+ 1 space-idx) lurk-input-marker)))
            (unless (string-prefix-p "/" (buffer-substring start end))
-             (completion-in-region start end (lurk-get-context-users lurk-current-context)))))))))
+             (let* ((users (lurk-get-context-users lurk-current-context))
+                    (users-no@ (mapcar
+                                (lambda (u) (car (split-string u "@" t)))
+                                users)))
+               (completion-in-region start end users-no@)))))))))
 
 (defun lurk-enter ()
   "Enter current contents of line after prompt."
@@ -1151,8 +1180,6 @@ in which case they match anything.")
         (kbd "TAB") 'lurk-complete-input))
     map))
 
-(defvar lurk-mode-map)
-
 (define-derived-mode lurk-mode text-mode "lurk"
   "Major mode for LURK.")