(lambda (proc string)
(unless (equal "open" (string-trim string))
(murk-display-error "Disconnected from server.")
- (murk-remove-contexts-for-server server)
+ (murk-remove-server-contexts server)
(murk-render-prompt)
(murk-connection-close server))))
(add-to-list 'murk-connection-table
(list server proc "")))
(murk-send-msg server (murk-msg nil nil "USER" murk-nick 0 "*" murk-nick))
- (murk-send-msg server (murk-msg nil nil "NICK" murk-nick)))))
+ (murk-send-msg server (murk-msg nil nil "NICK" murk-nick))
+ (murk-add-context (list server)))))
(defun murk-send-msg (server msg)
(if murk-debug
(defun murk-context-server (ctx) (elt ctx 0))
(defun murk-context-name (ctx) (elt ctx 1))
+(defun murk-add-context (ctx)
+ (add-to-list 'murk-contexts ctx))
+
+(defun murk-remove-server-contexts (server)
+ (setq murk-contexts
+ (assoc-delete-all server murk-contexts)))
+
;;; Buffer
;;
(insert
(propertize (let ((ctx (murk-current-context)))
(if ctx
- (concat (murk-context-name) "@" (murk-context-server ctx))
- ""))
+ (concat (murk-context-name) "@" (murk-context-server ctx))
+ ""))
'face 'murk-context
'read-only t)
(propertize murk-prompt-string
" " (number-to-string port) "]")))
(murk-display-notice nil "(Modify the `murk-networks' variable to add more.)"))
-
+(defun murk-command-quit (params)
+ (let ((ctx (murk-current-context)))
+ (if (not ctx)
+ (murk-display-error "No current context.")
+ (let ((quit-msg (if params (string-join params " ") murk-default-quit-msg)))
+ (murk-send-msg
+ (murk-context-server ctx)
+ (lurk-msg nil nil "QUIT" quit-msg))))))
;;; Command entering
;;
nil)))
(if (and command-row (elt command-row 2))
(funcall (elt command-row 2) params)
- (murk-send-msg (murk-msg nil nil (upcase cmd-str) params)))))
+ (murk-send-msg
+ (murk-context-server (murk-current-context))
+ (murk-msg nil nil (upcase cmd-str) params)))))
(_
(murk-display-error "Badly formed command.")))
(unless (string-empty-p string)
(delete-region murk-input-marker (point-max)))
(murk-enter-string line))))
+(defun murk-history-next ()
+ (interactive)
+ (murk-history-cycle -1))
+
+(defun murk-history-prev ()
+ (interactive)
+ (murk-history-cycle +1))
+
(defun murk-complete-input ()
(interactive)
(let ((completion-ignore-case t))
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") 'murk-enter)
(define-key map (kbd "TAB") 'murk-complete-input)
+ (define-key map (kbd "<C-up>") 'murk-history-prev)
+ (define-key map (kbd "<C-down>") 'murk-history-next)
(when (fboundp 'evil-define-key*)
(evil-define-key* 'motion map
(kbd "TAB") 'murk-complete-input))