From: Tim Vaughan Date: Mon, 5 Jul 2021 13:58:05 +0000 (+0200) Subject: Added nick completion. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=28b4ff917a9d70cc7cfec9e4773a05d512df158a;p=lurk.git Added nick completion. --- diff --git a/lurk.el b/lurk.el index 894f4b1..b22ca85 100644 --- a/lurk.el +++ b/lurk.el @@ -369,39 +369,6 @@ portion of the source component of the message, as LURK doesn't use this.") (goto-char (point-max)) (lurk-render-prompt))) -;;; URL buttons - -(defconst lurk-url-regex - (rx (: - (group (+ alpha)) - "://" - (group (or (+ (any alnum "." "-")) - (+ (any alnum ":")))) - (opt (group (: ":" (+ digit)))) - (opt (group (: "/" - (opt - (* (any alnum ",.-~/@|:%#=&_")) - (+ (any alnum "-~/@|:%#=&"))))))))) - -(defun lurk-click-url (button) - (browse-url (button-get button 'url))) - -(defun lurk-buttonify-urls (string) - "Turn substrings which look like urls in STRING into clickable buttons." - (with-temp-buffer - (insert string) - (goto-char (point-min)) - (while (re-search-forward lurk-url-regex nil t) - (let ((url (match-string 0))) - (make-text-button (match-beginning 0) - (match-end 0) - 'action #'lurk-click-url - 'url url - 'follow-link t - 'face 'button - 'help-echo "Open URL in browser."))) - (buffer-string))) - ;;; Output formatting and highlighting ;; @@ -417,7 +384,7 @@ portion of the source component of the message, as LURK doesn't use this.") ;; and for different elements of the context-specific text to have ;; different styling. -;; Additionally, we can allow selective hiding of contexts via +;; Additionally, we allow selective hiding of contexts via ;; the buffer-invisibility-spec. (defvar lurk-context-facelists (make-hash-table :test 'equal) @@ -516,6 +483,38 @@ portion of the source component of the message, as LURK doesn't use this.") lurk-context-facelists) (force-window-update "*lurk*"))) +(defconst lurk-url-regex + (rx (: + (group (+ alpha)) + "://" + (group (or (+ (any alnum "." "-")) + (+ (any alnum ":")))) + (opt (group (: ":" (+ digit)))) + (opt (group (: "/" + (opt + (* (any alnum ",.-~/@|:%#=&_")) + (+ (any alnum "-~/@|:%#=&"))))))))) + +(defun lurk-click-url (button) + (browse-url (button-get button 'url))) + +(defun lurk-buttonify-urls (string) + "Turn substrings which look like urls in STRING into clickable buttons." + (with-temp-buffer + (insert string) + (goto-char (point-min)) + (while (re-search-forward lurk-url-regex nil t) + (let ((url (match-string 0))) + (make-text-button (match-beginning 0) + (match-end 0) + 'action #'lurk-click-url + 'url url + 'follow-link t + 'face 'button + 'help-echo "Open URL in browser."))) + (buffer-string))) + + ;;; Message evaluation ;; @@ -749,9 +748,6 @@ portion of the source component of the message, as LURK doesn't use this.") (lurk-enter-string line)))) -;;; Command completion -;; - ;;; Interactive functions ;; @@ -773,13 +769,23 @@ portion of the source component of the message, as LURK doesn't use this.") (lurk-zoom-in lurk-current-context)) (setq lurk-zoomed (not lurk-zoomed))) +(defun lurk-complete-nick () + (interactive) + (when (and (>= (point) lurk-input-marker) lurk-current-context) + (let* ((end (max lurk-input-marker (point))) + (space-idx (save-excursion + (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)))))) + ;;; Mode ;; (defvar lurk-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "RET") 'lurk-enter) - (define-key map (kbd "") 'lurk-complete) + (define-key map (kbd "") 'lurk-complete-nick) (define-key map (kbd "C-c C-z") 'lurk-toggle-zoom) (define-key map (kbd "") 'lurk-cycle-contexts-forward) (define-key map (kbd "") 'lurk-cycle-contexts-reverse)