1 ;;; lurk.el --- Little Uni-buffer iRc Klient -*- lexical-binding:t -*-
3 ;; Copyright (C) 2021 Tim Vaughan
5 ;; Author: Tim Vaughan <timv@ughan.xyz>
6 ;; Created: 14 June 2021
9 ;; Homepage: http://thelambdalab.xyz/lurk
10 ;; Package-Requires: ((emacs "26"))
12 ;; This file is not part of GNU Emacs.
14 ;; This program is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this file. If not, see <http://www.gnu.org/licenses/>.
38 "Little Uni-buffer iRc Klient."
41 (defcustom lurk-nick "plugd"
44 (defcustom lurk-default-quit-msg "Bye"
45 "Default quit message when none supplied.")
47 (defcustom lurk-networks
48 '(("libera" "irc.libera.chat" 6697)
49 ("freenode" "chat.freenode.net" 6697)
50 ("tilde" "tilde.chat" 6697)
51 ("mbr" "mbrserver.com" 6667 :notls)
52 ("local" "localhost" 6697))
55 (defcustom lurk-allow-ipv6 nil
56 "Set to non-nil to allow use of IPv6.")
58 (defcustom lurk-show-joins nil
59 "Set to non-nil to be notified of joins, parts and quits.")
65 '((t :inherit default))
66 "Face used for Lurk text.")
69 '((t :inherit org-priority))
70 "Face used for the prompt.")
73 '((t :inherit org-tag))
74 "Face used for the context name in the prompt.")
77 '((t :inherit org-agenda-dimmed-todo-face))
78 "Face used for faded Lurk text.")
80 (defface lurk-timestamp
81 '((t :inherit org-agenda-dimmed-todo-face))
82 "Face used for timestamps.")
85 '((t :inherit font-lock-regexp-grouping-construct))
86 "Face used for Lurk error text.")
89 '((t :inherit org-upcoming-deadline))
90 "Face used for Lurk notice text.")
95 (defvar lurk-version "Lurk v0.1"
96 "Value of this string is used in response to CTCP version queries.")
98 (defvar lurk-notice-prefix "-!-")
100 (defvar lurk-error-prefix "!!!")
102 (defvar lurk-prompt-string ">")
104 (defvar lurk-debug nil
105 "If non-nil, enable debug mode.")
110 (defvar lurk-response "")
112 (defun lurk-filter (proc string)
113 (dolist (line (split-string (concat lurk-response string) "\n"))
114 (if (string-suffix-p "\r" line)
115 (lurk-eval-msg-string (string-trim line))
116 (setq lurk-response line))))
118 (defun lurk-sentinel (proc string)
119 (unless (equal "open" (string-trim string))
120 (lurk-display-error "Disconnected from server.")
121 (clrhash lurk-contexts)
122 (lurk-set-current-context nil)
124 (cancel-timer lurk-ping-timer)))
126 (defun lurk-start-process (network)
127 (let* ((row (assoc network lurk-networks))
130 (flags (seq-drop row 3)))
131 (make-network-process :name "lurk"
134 :family (if lurk-allow-ipv6 nil 'ipv4)
135 :filter #'lurk-filter
136 :sentinel #'lurk-sentinel
138 :tls-parameters (if (memq :notls flags)
140 (cons 'gnutls-x509pki
141 (gnutls-boot-parameters
142 :type 'gnutls-x509pki
146 (defvar lurk-ping-timer nil)
147 (defvar lurk-ping-period 60)
149 (defun lurk-ping-function ()
150 (lurk-send-msg (lurk-msg nil nil "PING" (car (process-contact (get-process "lurk")))))
151 (setq lurk-ping-timer (run-with-timer lurk-ping-period nil #'lurk-ping-function)))
153 (defun lurk-connect (network)
154 (if (get-process "lurk")
155 (lurk-display-error "Already connected. Disconnect first.")
156 (if (not (assoc network lurk-networks))
157 (lurk-display-error "Network '" network "' is unknown.")
158 (clrhash lurk-contexts)
159 (lurk-set-current-context nil)
160 (lurk-start-process network)
161 (lurk-send-msg (lurk-msg nil nil "USER" lurk-nick 0 "*" lurk-nick))
162 (lurk-send-msg (lurk-msg nil nil "NICK" lurk-nick))
163 (setq lurk-ping-timer (run-with-timer lurk-ping-period nil #'lurk-ping-function)))))
165 (defun lurk-connected-p ()
166 (let ((proc (get-process "lurk")))
167 (and proc (eq (process-status proc) 'open))))
169 (defun lurk-send-msg (msg)
171 (lurk-display-string nil nil (lurk-msg->string msg)))
172 (let ((proc (get-process "lurk")))
173 (if (and proc (eq (process-status proc) 'open))
174 (process-send-string proc (concat (lurk-msg->string msg) "\r\n"))
175 (lurk-display-error "No server connection established.")
176 (error "No server connection established"))))
182 (defun lurk--as-string (obj)
184 (with-output-to-string (princ obj))
187 (defun lurk-msg (tags src cmd &rest params)
188 (list (lurk--as-string tags)
189 (lurk--as-string src)
190 (upcase (lurk--as-string cmd))
191 (mapcar #'lurk--as-string
192 (if (and params (listp (elt params 0)))
196 (defun lurk-msg-tags (msg) (elt msg 0))
197 (defun lurk-msg-src (msg) (elt msg 1))
198 (defun lurk-msg-cmd (msg) (elt msg 2))
199 (defun lurk-msg-params (msg) (elt msg 3))
200 (defun lurk-msg-trail (msg)
201 (let ((params (lurk-msg-params msg)))
203 (elt params (- (length params) 1)))))
205 (defvar lurk-msg-regex
207 (opt (: "@" (group (* (not (or "\n" "\r" ";" " ")))))
209 (opt (: ":" (: (group (* (not (any space "!" "@"))))
210 (* (not (any space)))))
212 (group (: (* (not whitespace))))
214 (opt (group (+ not-newline))))
215 "Regex used to parse IRC messages.
216 Note that this regex is incomplete. Noteably, we discard the non-nick
217 portion of the source component of the message, as LURK doesn't use this.")
219 (defun lurk-string->msg (string)
220 (if (string-match lurk-msg-regex string)
221 (let* ((tags (match-string 1 string))
222 (src (match-string 2 string))
223 (cmd (upcase (match-string 3 string)))
224 (params-str (match-string 4 string))
227 (let* ((idx (cl-search ":" params-str))
228 (l (split-string (string-trim (substring params-str 0 idx))))
229 (r (if idx (list (substring params-str (+ 1 idx))) nil)))
232 (apply #'lurk-msg (append (list tags src cmd) params)))
233 (error "Failed to parse string " string)))
235 (defun lurk--filtered-join (&rest args)
236 (string-join (seq-filter (lambda (el) el) args) " "))
238 (defun lurk-msg->string (msg)
239 (let ((tags (lurk-msg-tags msg))
240 (src (lurk-msg-src msg))
241 (cmd (lurk-msg-cmd msg))
242 (params (lurk-msg-params msg)))
244 (if tags (concat "@" tags) nil)
245 (if src (concat ":" src) nil)
247 (if (> (length params) 1)
248 (string-join (seq-take params (- (length params) 1)) " ")
250 (if (> (length params) 0)
251 (concat ":" (elt params (- (length params) 1)))
258 (defvar lurk-current-context nil)
259 (defvar lurk-contexts (make-hash-table :test #'equal))
261 (defun lurk-add-context (name)
262 (puthash name nil lurk-contexts))
264 (defun lurk-del-context (name)
265 (remhash name lurk-contexts))
267 (defun lurk-get-context-users (name)
268 (gethash name lurk-contexts))
270 (defun lurk-add-context-users (context users)
273 (gethash context lurk-contexts))
276 (defun lurk-del-context-user (context user)
278 (remove user (gethash context lurk-contexts))
281 (defun lurk-del-user (user)
282 (dolist (context (lurk-get-context-list))
283 (lurk-del-context-user context user)))
285 (defun lurk-rename-user (old-nick new-nick)
286 (dolist (context (lurk-get-context-list))
287 (lurk-del-context-user context old-nick)
288 (lurk-add-context-users context (list new-nick))))
290 (defun lurk-get-context-type (name)
292 ((string-prefix-p "#" name) 'channel)
293 ((string-match-p (rx (or "." "localhost")) name) 'host)
296 (defun lurk-get-context-list ()
298 (maphash (lambda (key val)
299 (cl-pushnew key res))
303 (defun lurk-get-next-context (&optional prev)
304 (if lurk-current-context
305 (let* ((context-list (if prev
306 (reverse (lurk-get-context-list))
307 (lurk-get-context-list)))
308 (context-list* (member lurk-current-context context-list)))
309 (if (> (length context-list*) 1)
314 (defun lurk-set-current-context (context)
315 (setq lurk-current-context context)
316 (lurk-highlight-context context)
318 (lurk-zoom-in lurk-current-context)))
320 (defun lurk-cycle-contexts (&optional rev)
321 (if lurk-current-context
323 (lurk-set-current-context (lurk-get-next-context rev))
324 (lurk-render-prompt))
325 (lurk-display-error "No channels joined.")))
331 (defun lurk-render-prompt ()
332 (with-current-buffer "*lurk*"
333 (let ((update-point (= lurk-input-marker (point)))
334 (update-window-points (mapcar (lambda (w)
335 (list (= (window-point w) lurk-input-marker)
337 (get-buffer-window-list nil nil t))))
339 (set-marker-insertion-type lurk-prompt-marker nil)
340 (set-marker-insertion-type lurk-input-marker t)
341 (let ((inhibit-read-only t))
342 (delete-region lurk-prompt-marker lurk-input-marker)
343 (goto-char lurk-prompt-marker)
345 (propertize (if lurk-current-context
350 (propertize (concat lurk-prompt-string " ")
354 (set-marker-insertion-type lurk-input-marker nil))
356 (goto-char lurk-input-marker))
357 (dolist (v update-window-points)
359 (set-window-point (cadr v) lurk-input-marker))))))
361 (defvar lurk-prompt-marker nil
362 "Marker for prompt position in LURK buffer.")
364 (defvar lurk-input-marker nil
365 "Marker for prompt position in LURK buffer.")
367 (defun lurk-setup-buffer ()
368 (with-current-buffer (get-buffer-create "*lurk*")
369 (setq-local scroll-conservatively 1)
370 (setq-local buffer-invisibility-spec nil)
371 (if (markerp lurk-prompt-marker)
372 (set-marker lurk-prompt-marker (point-max))
373 (setq lurk-prompt-marker (point-max-marker)))
374 (if (markerp lurk-input-marker)
375 (set-marker lurk-input-marker (point-max))
376 (setq lurk-input-marker (point-max-marker)))
377 (goto-char (point-max))
378 (lurk-render-prompt)))
381 ;;; Output formatting and highlighting
384 ;; Partially-implemented idea: the face text property can be
385 ;; a list of faces, applied in order. By assigning each context
386 ;; a unique list and keeping track of these in a hash table, we can
387 ;; easily switch the face corresponding to a particular context
388 ;; by modifying the elements of this list.
390 ;; More subtly, we make only the cdrs of this list shared among
391 ;; all text of a given context, allowing the cars to be different
392 ;; and for different elements of the context-specific text to have
393 ;; different styling.
395 ;; Additionally, we allow selective hiding of contexts via
396 ;; the buffer-invisibility-spec.
398 (defvar lurk-context-facelists (make-hash-table :test 'equal)
399 "List of seen contexts and associated face lists.")
401 (defun lurk-get-context-facelist (context)
402 (let ((facelist (gethash context lurk-context-facelists)))
404 (setq facelist (list 'lurk-text))
405 (puthash context facelist lurk-context-facelists))
408 (defun lurk-display-string (context prefix &rest strings)
409 (with-current-buffer (get-buffer-create "*lurk*")
411 (goto-char lurk-prompt-marker)
412 (let* ((inhibit-read-only t)
413 (old-pos (marker-position lurk-prompt-marker))
414 (padded-timestamp (concat (format-time-string "%H:%M ")))
415 (padded-prefix (if prefix (concat prefix " ") ""))
416 (adaptive-fill-regexp (rx-to-string
417 `(= ,(+ (length padded-timestamp)
418 (length padded-prefix))
421 (context-atom (if context (intern context) nil)))
422 (insert-before-markers
423 (propertize padded-timestamp
424 'face 'lurk-timestamp
427 'invisible context-atom)
428 (propertize padded-prefix
431 'invisible context-atom)
432 (propertize (concat (lurk-buttonify-urls (apply #'concat strings)) "\n")
433 'face (lurk-get-context-facelist context)
436 'invisible context-atom))
437 (fill-region old-pos lurk-prompt-marker nil t)))))
439 (defun lurk-display-message (from to text)
440 (let ((context (if (eq 'channel (lurk-get-context-type to))
442 (if (equal to lurk-nick) from to))))
445 (pcase (lurk-get-context-type to)
446 ('channel (concat to " <" from ">"))
447 ('nick (concat "[" from " -> " to "]"))
449 (error "Unsupported context type")))
452 (defun lurk-display-action (from to action-text)
453 (let ((context (if (eq 'channel (lurk-get-context-type to))
455 (if (equal to lurk-nick) from to))))
461 (defun lurk-display-notice (context &rest notices)
464 (propertize lurk-notice-prefix 'face 'lurk-notice)
465 (apply #'concat notices)))
467 (defun lurk-display-error (&rest messages)
470 (propertize lurk-error-prefix 'face 'lurk-error)
471 (apply #'concat messages)))
473 (defun lurk-highlight-context (context)
475 (lambda (this-context facelist)
476 (if (equal this-context context)
477 (setcar facelist 'lurk-text)
478 (setcar facelist 'lurk-faded)))
479 lurk-context-facelists)
480 (force-window-update "*lurk*"))
482 (defun lurk-zoom-in (context)
483 (with-current-buffer "*lurk*"
485 (lambda (this-context _)
487 (let ((this-context-atom (intern this-context)))
488 (if (equal this-context context)
489 (remove-from-invisibility-spec this-context-atom)
490 (add-to-invisibility-spec this-context-atom)))))
491 lurk-context-facelists)
492 (force-window-update "*lurk*")))
494 (defun lurk-zoom-out ()
495 (with-current-buffer "*lurk*"
497 (lambda (this-context _)
498 (let ((this-context-atom (if this-context (intern this-context) nil)))
499 (remove-from-invisibility-spec this-context-atom)))
500 lurk-context-facelists)
501 (force-window-update "*lurk*")))
503 (defconst lurk-url-regex
507 (group (or (+ (any alnum "." "-"))
508 (+ (any alnum ":"))))
509 (opt (group (: ":" (+ digit))))
512 (* (any alnum ",.-~/@|:%#=&_"))
513 (+ (any alnum "-~/@|:%#=&")))))))))
515 (defun lurk-click-url (button)
516 (browse-url (button-get button 'url)))
518 (defun lurk-buttonify-urls (string)
519 "Turn substrings which look like urls in STRING into clickable buttons."
522 (goto-char (point-min))
523 (while (re-search-forward lurk-url-regex nil t)
524 (let ((url (match-string 0)))
525 (make-text-button (match-beginning 0)
527 'action #'lurk-click-url
531 'help-echo "Open URL in browser.")))
535 ;;; Message evaluation
538 (defun lurk-eval-msg-string (string)
540 (lurk-display-string nil nil string))
541 (let* ((msg (lurk-string->msg string)))
542 (pcase (lurk-msg-cmd msg)
545 (lurk-msg nil nil "PONG" (lurk-msg-params msg))))
546 ;; (lurk-display-notice nil "ping-pong (server initiated)"))
549 ;; (lurk-display-notice nil "ping-pong (client initiated)"))
552 (let* ((params (lurk-msg-params msg))
553 (nick (elt params 0))
554 (text (string-join (seq-drop params 1) " ")))
555 (setq lurk-nick nick)
556 (lurk-display-notice nil text)))
559 (let* ((params (lurk-msg-params msg))
560 (channel (elt params 2))
561 (names (split-string (elt params 3))))
562 (lurk-add-context-users channel names)))
565 (let* ((params (lurk-msg-params msg))
566 (channel (elt params 1)))
569 (lurk--as-string (length (lurk-get-context-users channel)))
570 " users in " channel)))
573 (let* ((params (lurk-msg-params msg))
574 (channel (elt params 1)))
580 (let* ((params (lurk-msg-params msg))
581 (channel (elt params 1))
582 (topic (elt params 2)))
583 (lurk-display-notice channel "Topic: " topic)))
585 ("333") ; Avoid displaying these
587 ((rx (= 3 (any digit)))
588 (lurk-display-notice nil (mapconcat 'identity (cdr (lurk-msg-params msg)) " ")))
591 (guard (equal lurk-nick (lurk-msg-src msg))))
592 (let ((channel (car (lurk-msg-params msg))))
593 (lurk-add-context channel)
594 (lurk-set-current-context channel)
595 (lurk-display-notice channel "Joining channel " channel)
596 (lurk-render-prompt)))
599 (let ((channel (car (lurk-msg-params msg)))
600 (nick (lurk-msg-src msg)))
601 (lurk-add-context-users channel (list nick))
603 (lurk-display-notice channel nick " joined channel " channel))))
606 (guard (equal lurk-nick (lurk-msg-src msg))))
607 (let ((channel (car (lurk-msg-params msg))))
608 (lurk-display-notice channel "Left channel " channel)
609 (lurk-del-context channel)
610 (if (equal channel lurk-current-context)
611 (lurk-set-current-context (lurk-get-next-context)))
612 (lurk-render-prompt)))
615 (let ((channel (car (lurk-msg-params msg)))
616 (nick (lurk-msg-src msg)))
617 (lurk-del-context-user channel nick)
619 (lurk-display-notice channel nick " left channel " channel))))
622 (let ((nick (lurk-msg-src msg))
623 (reason (mapconcat 'identity (lurk-msg-params msg) " ")))
626 (lurk-display-notice nil nick " quit: " reason))))
629 (guard (equal lurk-nick (lurk-msg-src msg))))
630 (setq lurk-nick (car (lurk-msg-params msg)))
631 (lurk-display-notice nil "Set nick to " lurk-nick))
634 (let ((old-nick (lurk-msg-src msg))
635 (new-nick (car (lurk-msg-params msg))))
636 (lurk-display-notice nil old-nick " is now known as " new-nick)
637 (lurk-rename-user old-nick new-nick)))
640 (let ((nick (lurk-msg-src msg))
641 (channel (car (lurk-msg-params msg)))
642 (text (cadr (lurk-msg-params msg))))
644 ((rx (: "\01VERSION "
645 (let version (* (not "\01")))
647 (lurk-display-notice nil "CTCP version reply from " nick ": " version))
649 (lurk-display-notice nil text)))))
652 (let* ((from (lurk-msg-src msg))
653 (params (lurk-msg-params msg))
655 (text (cadr params)))
658 (let ((version-string (concat lurk-version " - running on GNU Emacs " emacs-version)))
659 (lurk-send-msg (lurk-msg nil nil "NOTICE"
660 (list from (concat "\01VERSION "
663 (lurk-display-notice nil "CTCP version request received from " from))
665 ((rx (let ping (: "\01PING " (* (not "\01")) "\01")))
666 (lurk-send-msg (lurk-msg nil nil "NOTICE" (list from ping)))
667 (lurk-display-notice from "CTCP ping received from " from))
670 (lurk-display-notice from "CTCP userinfo request from " from " (no response sent)"))
672 ((rx (: "\01ACTION " (let action-text (* (not "\01"))) "\01"))
673 (lurk-display-action from to action-text))
676 (lurk-display-message from to text)))))
678 (lurk-display-notice nil (lurk-msg->string msg))))))
684 (defun lurk-enter-string (string)
685 (if (string-prefix-p "/" string)
686 (pcase (substring string 1)
688 (setq lurk-debug (not lurk-debug))
689 (lurk-display-notice nil "Debug mode now " (if lurk-debug "on" "off") "."))
691 ((rx (: "CONNECT " (let network (* not-newline))))
692 (lurk-display-notice nil "Attempting to connect to " network "...")
693 (lurk-connect network))
695 ((rx (: "TOPIC " (let new-topic (* not-newline))))
696 (lurk-send-msg (lurk-msg nil nil "TOPIC" lurk-current-context new-topic)))
698 ((rx (: "ME " (let action (* not-newline))))
699 (let ((ctcp-text (concat "\01ACTION " action "\01")))
700 (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
701 (list lurk-current-context ctcp-text)))
702 (lurk-display-action lurk-nick lurk-current-context action)))
704 ((rx (: "VERSION" " " (let nick (+ (not whitespace)))))
705 (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
706 (list nick "\01VERSION\01")))
707 (lurk-display-notice nil "CTCP version request sent to " nick))
709 ((rx "PART" (opt (: " " (let channel (* not-newline)))))
710 (if (or lurk-current-context channel)
711 (lurk-send-msg (lurk-msg nil nil "PART" (if channel
713 lurk-current-context)))
714 (lurk-display-error "No current channel to leave.")))
716 ((rx "QUIT" (opt (: " " (let quit-msg (* not-newline)))))
717 (lurk-send-msg (lurk-msg nil nil "QUIT"
718 (or quit-msg lurk-default-quit-msg))))
720 ((rx (: "NICK" (* whitespace) string-end))
721 (lurk-display-notice nil "Current nick: " lurk-nick))
723 ((rx (: "NICK" (+ whitespace) (let nick (+ (not whitespace)))))
724 (if (lurk-connected-p)
725 (lurk-send-msg (lurk-msg nil nil "NICK" nick))
726 (setq lurk-nick nick)
727 (lurk-display-notice nil "Set default nick to '" nick "'")))
730 (lurk-display-notice nil "This command can generate lots of output. Use `LIST -yes' if you're sure."))
732 ((rx (: "LIST" (+ whitespace) "-YES"))
733 (lurk-send-msg (lurk-msg nil nil "LIST")))
736 (let to (* (not whitespace)))
738 (let text (* not-newline)))
739 (lurk-send-msg (lurk-msg nil nil "PRIVMSG" to text))
740 (lurk-display-message lurk-nick to text))
742 ((rx (: (let cmd-str (+ (not whitespace)))
743 (opt (: " " (let params-str (* not-newline))))))
744 (lurk-send-msg (lurk-msg nil nil (upcase cmd-str)
746 (split-string params-str)
749 (unless (string-empty-p string)
750 (if lurk-current-context
752 (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
755 (lurk-display-message lurk-nick lurk-current-context string))
756 (lurk-display-error "No current context.")))))
758 (defvar lurk-history nil
759 "Commands and messages sent in current session.")
763 "Enter current contents of line after prompt."
765 (with-current-buffer "*lurk*"
766 (let ((line (buffer-substring lurk-input-marker (point-max))))
767 (push line lurk-history)
768 (setq lurk-history-index nil)
769 (let ((inhibit-read-only t))
770 (delete-region lurk-input-marker (point-max)))
771 (lurk-enter-string line))))
773 (defvar lurk-history-index nil)
775 (defun lurk-history-cycle (delta)
777 (with-current-buffer "*lurk*"
778 (if lurk-history-index
779 (setq lurk-history-index
781 (min (- (length lurk-history) 1)
782 (+ delta lurk-history-index))))
783 (setq lurk-history-index 0))
784 (delete-region lurk-input-marker (point-max))
785 (insert (elt lurk-history lurk-history-index)))))
787 (defun lurk-history-next ()
789 (lurk-history-cycle -1))
791 (defun lurk-history-prev ()
793 (lurk-history-cycle +1))
795 ;;; Interactive functions
798 (defun lurk-cycle-contexts-forward ()
800 (lurk-cycle-contexts))
802 (defun lurk-cycle-contexts-reverse ()
804 (lurk-cycle-contexts t))
806 (defvar lurk-zoomed nil
807 "Keeps track of zoom status.")
809 (defun lurk-toggle-zoom ()
813 (lurk-zoom-in lurk-current-context))
814 (setq lurk-zoomed (not lurk-zoomed)))
816 (defun lurk-complete-nick ()
818 (when (and (>= (point) lurk-input-marker) lurk-current-context)
819 (let* ((end (max lurk-input-marker (point)))
820 (space-idx (save-excursion
821 (re-search-backward " " lurk-input-marker t)))
822 (start (if space-idx (+ 1 space-idx) lurk-input-marker)))
823 (unless (string-prefix-p "/" (buffer-substring start end))
824 (completion-in-region start end (lurk-get-context-users lurk-current-context))))))
830 (defvar lurk-mode-map
831 (let ((map (make-sparse-keymap)))
832 (define-key map (kbd "RET") 'lurk-enter)
833 (define-key map (kbd "<tab>") 'lurk-complete-nick)
834 (define-key map (kbd "C-c C-z") 'lurk-toggle-zoom)
835 (define-key map (kbd "<C-tab>") 'lurk-cycle-contexts-forward)
836 (define-key map (kbd "<C-S-tab>") 'lurk-cycle-contexts-reverse)
837 (define-key map (kbd "<C-up>") 'lurk-history-prev)
838 (define-key map (kbd "<C-down>") 'lurk-history-next)
839 ;; (when (fboundp 'evil-define-key*)
840 ;; (evil-define-key* 'insert map
841 ;; (kbd "<C-Up>") 'lurk-history-prev
842 ;; (kbd "<C-Down>") 'lurk-history-next))
845 (defvar lurk-mode-map)
847 (define-derived-mode lurk-mode text-mode "lurk"
848 "Major mode for LURK.")
850 (when (fboundp 'evil-set-initial-state)
851 (evil-set-initial-state 'lurk-mode 'insert))
853 ;;; Main start procedure
857 "Switch to *lurk* buffer."
859 (if (get-buffer "*lurk*")
860 (switch-to-buffer "*lurk*")
861 (switch-to-buffer "*lurk*")
867 ;;; lurk.el ends here