(defun lurk-get-context-users (name)
(gethash name lurk-contexts))
+(defun lurk-context-known-p (name)
+ (not (eq (gethash name lurk-contexts 0) 0)))
+
(defun lurk-add-context-users (context users)
(puthash context
- (append users
- (gethash context lurk-contexts))
+ (cl-union users
+ (gethash context lurk-contexts))
lurk-contexts))
(defun lurk-del-context-user (context user)
(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.")))
(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
;;
(fill-region (point-min) (point-max) nil t)
(buffer-string))))
+(defun lurk--start-of-final-line ()
+ (with-current-buffer "*lurk*"
+ (save-excursion
+ (goto-char (point-max))
+ (line-beginning-position))))
+
+(defun lurk-scroll-windows-to-last-line ()
+ (with-current-buffer "*lurk*"
+ (dolist (window (get-buffer-window-list))
+ (if (>= (window-point window) (lurk--start-of-final-line))
+ (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)
+ (lurk-set-current-context (button-get button 'context)))
+
(defun lurk-display-string (context prefix &rest strings)
- (with-current-buffer (get-buffer-create "*lurk*")
+ (with-current-buffer "*lurk*"
(save-excursion
(goto-char lurk-prompt-marker)
(let* ((inhibit-read-only t)
'face (lurk-get-context-facelist context)
'read-only t
'context context
- 'invisible context-atom))))))))
+ 'invisible context-atom)))))))
+ (lurk-scroll-windows-to-last-line))
(defun lurk-display-message (from to text)
(let ((context (if (eq 'channel (lurk-get-context-type to))
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))
(lurk-display-string
context
(propertize
- (concat context " * " from)
+ (concat (lurk-make-context-button context) " * " from)
'face (lurk-get-context-facelist context))
action-text)))
(remove-from-invisibility-spec this-context-atom)
(add-to-invisibility-spec this-context-atom)))))
lurk-context-facelists)
- (force-window-update "*lurk*")))
+ (force-window-update "*lurk*"))
+ (lurk-scroll-windows-to-last-line))
(defun lurk-zoom-out ()
(with-current-buffer "*lurk*"
(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*")))
+ (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 (:
(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)))
(let* ((params (lurk-msg-params msg))
(channel (elt params 2))
(names (split-string (elt params 3))))
- (lurk-add-context-users channel names)))
+ (if (lurk-context-known-p channel)
+ (lurk-add-context-users channel names)
+ (lurk-display-notice nil "Users in " channel ": " (string-join names " ")))))
("366" ; ENDOFNAMES
(let* ((params (lurk-msg-params msg))
(channel (elt params 1)))
- (lurk-display-notice
- channel
- (lurk--as-string (length (lurk-get-context-users channel)))
- " users in " channel)))
+ (if (lurk-context-known-p channel)
+ (lurk-display-notice
+ channel
+ (lurk--as-string (length (lurk-get-context-users channel)))
+ " users in " channel)
+ (lurk-display-notice nil "End of " channel " names list."))))
("331"
(let* ((params (lurk-msg-params msg))
("HEADER" "Toggle display of header." lurk-command-header lurk-boolean-completions)
("CONNECT" "Connect to an IRC network." lurk-command-connect lurk-network-completions)
("NETWORKS" "List known IRC networks." lurk-command-networks)
+ ("JOIN" "Join one or more channels." lurk-command-join)
("TOPIC" "Set topic for current channel." lurk-command-topic)
("ME" "Display action." lurk-command-me)
- ("VERSION" "Request version of another user's client via CTCP." lurk-command-version)
+ ("VERSION" "Request version of another user's client via CTCP." lurk-command-version lurk-nick-completions)
("PART" "Leave channel." lurk-command-part lurk-context-completions)
("QUIT" "Disconnect from current network." lurk-command-quit)
("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)
("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.")
" " (number-to-string port) "]")))
(lurk-display-notice nil "(Modify the `lurk-networks' variable to add more.)"))
+(defun lurk-command-join (params)
+ (if params
+ (dolist (channel params)
+ (lurk-send-msg (lurk-msg nil nil "JOIN" channel)))
+ (lurk-display-notice nil "Usage: /join channel [channel2 ...]")))
+
(defun lurk-command-part (params)
(let ((channel (if params (car params) lurk-current-context)))
(if channel
(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
;;
(params (if params-str
(split-string params-str nil t)
nil)))
- (if command-row
+ (if (and command-row (elt command-row 2))
(funcall (elt command-row 2) params)
(lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params)))))
(_