"")
'face 'lurk-context
'read-only t)
- (propertize (concat lurk-prompt-string " ")
+ (propertize lurk-prompt-string
'face 'lurk-prompt
+ 'read-only t)
+ (propertize " " ; Need this to be separate to mark it as rear-nonsticky
'read-only t
'rear-nonsticky t)))
(set-marker-insertion-type lurk-input-marker nil))
("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)
- ("MSG" "Send private message to user." lurk-command-msg lurk-nick-completions))
+ ("MSG" "Send private message to user." lurk-command-msg lurk-nick-completions)
+ ("HELP" "Display help on client commands." lurk-command-help lurk-help-completions))
"Table of commands explicitly supported by Lurk.")
(defun lurk-boolean-completions ()
(defun lurk-context-completions ()
(lurk-get-context-list))
+(defun lurk-help-completions ()
+ (mapcar (lambda (row) (car row)) lurk-command-table))
-;;; Command entering
-;;
-
-(defun lurk-enter-string (string)
- (if (string-prefix-p "/" string)
- (pcase string
- ((rx (: "/" (let cmd-str (+ (not whitespace)))
- (opt (+ whitespace)
- (let params-str (+ anychar))
- string-end)))
- (let ((command-row (assoc (upcase cmd-str) lurk-command-table #'equal))
- (params (if params-str
- (split-string params-str nil t)
- nil)))
- (if command-row
- (funcall (elt command-row 2) params)
- (lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params)))))
- (_
- (lurk-display-error "Badly formed command.")))
- (unless (string-empty-p string)
- (if lurk-current-context
- (progn
- (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
- lurk-current-context
- string))
- (lurk-display-message lurk-nick lurk-current-context string))
- (lurk-display-error "No current context.")))))
+(defun lurk-command-help (params)
+ (if params
+ (let* ((cmd-str (upcase (car params)))
+ (row (assoc cmd-str lurk-command-table #'equal)))
+ (if row
+ (progn
+ (lurk-display-notice nil "Help for \x02" cmd-str "\x02:")
+ (lurk-display-notice nil " " (elt row 1)))
+ (lurk-display-notice nil "No such (client-interpreted) command.")))
+ (lurk-display-notice nil "Client-interpreted commands:")
+ (dolist (row lurk-command-table)
+ (lurk-display-notice nil " \x02" (elt row 0) "\x02: " (elt row 1)))
+ (lurk-display-notice nil "Use /HELP COMMAND to display information about a specific command.")))
(defun lurk-command-debug (params)
(setq lurk-debug
(lurk-display-notice nil "No current channel.")))
(defun lurk-command-msg (params)
- (if (and params (>= 2 (length params)))
+ (if (and params (>= (length params) 2))
(let ((to (car params))
(text (string-join (cdr params) " ")))
(lurk-send-msg (lurk-msg nil nil "PRIVMSG" to text))
(lurk-display-notice nil "Usage: /msg <nick> <message>")))
+;;; Command entering
+;;
+
+(defun lurk-enter-string (string)
+ (if (string-prefix-p "/" string)
+ (pcase string
+ ((rx (: "/" (let cmd-str (+ (not whitespace)))
+ (opt (+ whitespace)
+ (let params-str (+ anychar))
+ string-end)))
+ (let ((command-row (assoc (upcase cmd-str) lurk-command-table #'equal))
+ (params (if params-str
+ (split-string params-str nil t)
+ nil)))
+ (if command-row
+ (funcall (elt command-row 2) params)
+ (lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params)))))
+ (_
+ (lurk-display-error "Badly formed command.")))
+ (unless (string-empty-p string)
+ (if lurk-current-context
+ (progn
+ (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
+ lurk-current-context
+ string))
+ (lurk-display-message lurk-nick lurk-current-context string))
+ (lurk-display-error "No current context.")))))
+
+
;;; Command history
;;
(defvar lurk-history nil
"Commands and messages sent in current session.")
-
-(defun lurk-enter ()
- "Enter current contents of line after prompt."
- (interactive)
- (with-current-buffer "*lurk*"
- (let ((line (buffer-substring lurk-input-marker (point-max))))
- (push line lurk-history)
- (setq lurk-history-index nil)
- (let ((inhibit-read-only t))
- (delete-region lurk-input-marker (point-max)))
- (lurk-enter-string line))))
-
(defvar lurk-history-index nil)
(defun lurk-history-cycle (delta)
(delete-region lurk-input-marker (point-max))
(insert (elt lurk-history lurk-history-index)))))
-(defun lurk-history-next ()
- (interactive)
- (lurk-history-cycle -1))
-
-(defun lurk-history-prev ()
- (interactive)
- (lurk-history-cycle +1))
-
;;; Interactive functions
;;
(lurk-zoom-in lurk-current-context))
(setq lurk-zoomed (not lurk-zoomed)))
+(defun lurk-history-next ()
+ (interactive)
+ (lurk-history-cycle -1))
+
+(defun lurk-history-prev ()
+ (interactive)
+ (lurk-history-cycle +1))
+
(defun lurk-complete-input ()
(interactive)
(let ((completion-ignore-case t))
(re-search-backward " " lurk-input-marker t)))
(table-row (assoc (upcase cmd-str) lurk-command-table #'equal)))
(if (and table-row (elt table-row 3))
- (let ((completions (funcall (elt table-row 3))))
+ (let* ((completions-nospace (funcall (elt table-row 3)))
+ (completions (mapcar (lambda (el) (concat el " ")) completions-nospace)))
(completion-in-region (+ 1 space-idx) (point) completions)))))
((rx (: "/" (* (not whitespace)) string-end))
(message (buffer-substring lurk-input-marker (point)))
(completion-in-region lurk-input-marker (point)
- (mapcar (lambda (row) (string-join (list "/" (car row))))
+ (mapcar (lambda (row) (concat "/" (car row) " "))
lurk-command-table)))
(_
(let* ((end (max lurk-input-marker (point)))
(unless (string-prefix-p "/" (buffer-substring start end))
(completion-in-region start end (lurk-get-context-users lurk-current-context)))))))))
+(defun lurk-enter ()
+ "Enter current contents of line after prompt."
+ (interactive)
+ (with-current-buffer "*lurk*"
+ (let ((line (buffer-substring lurk-input-marker (point-max))))
+ (push line lurk-history)
+ (setq lurk-history-index nil)
+ (let ((inhibit-read-only t))
+ (delete-region lurk-input-marker (point-max)))
+ (lurk-enter-string line))))
+
+
;;; Mode
;;
(when (fboundp 'evil-set-initial-state)
(evil-set-initial-state 'lurk-mode 'insert))
+
;;; Main start procedure
;;
-(defun lurk ()
- "Switch to *lurk* buffer."
+(defun lurk (&optional network)
+ "Start lurk or just switch to the lurk buffer if one already exists.
+Also connect to NETWORK if non-nil."
(interactive)
(if (get-buffer "*lurk*")
(switch-to-buffer "*lurk*")
(switch-to-buffer "*lurk*")
(lurk-mode)
- (lurk-setup-buffer))
+ (lurk-setup-buffer)
+ (if network
+ (lurk-command-connect (list network))))
"Started LURK.")