aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/erc
diff options
context:
space:
mode:
authorStefan Monnier2015-03-16 14:49:01 -0400
committerStefan Monnier2015-03-16 14:49:01 -0400
commitf925fc93bac41d7622d1af927e33b0e738ff55b0 (patch)
treee8635662256290a1662a299b66e32f6301535200 /lisp/erc
parent43a847c02c3eb848cd0d55a4722bfe7f39b1112f (diff)
downloademacs-f925fc93bac41d7622d1af927e33b0e738ff55b0.tar.gz
emacs-f925fc93bac41d7622d1af927e33b0e738ff55b0.zip
Add `predicate' arg to `read-buffer' and use it for erc-iswitchb
Fixes: debbugs:20116 * src/minibuf.c (Fread_buffer): Add `predicate' argument. * src/callint.c (Fcall_interactively): Adjust calls accordingly. * lisp/erc/erc.el (erc-switch-to-buffer): Rename from erc-iswitchb and rewrite using read-buffer. (erc--buffer-p): New function, extracted from erc-buffer-filter. (erc-buffer-filter): Use it. (erc-with-all-buffers-of-server): Silence compile warning if the return value is unused. (erc-is-valid-nick-p, erc-common-server-suffixes, erc-get-arglist) (erc-command-name, erc-popup-input-buffer): Use \` and \' to match beg/end of string. * lisp/obsolete/iswitchb.el (iswitchb-read-buffer): Add `predicate' arg. * lisp/isearchb.el (isearchb-iswitchb): Adjust accordingly. * lisp/ido.el (ido-read-buffer): Add `predicate' argument. * lisp/misearch.el (unload-function-defs-list): Declare before use.
Diffstat (limited to 'lisp/erc')
-rw-r--r--lisp/erc/ChangeLog12
-rw-r--r--lisp/erc/erc.el99
2 files changed, 58 insertions, 53 deletions
diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog
index 4f5fced1bd5..e75b8cc0078 100644
--- a/lisp/erc/ChangeLog
+++ b/lisp/erc/ChangeLog
@@ -1,3 +1,15 @@
12015-03-16 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * erc.el (erc-switch-to-buffer): Rename from erc-iswitchb and rewrite
4 using read-buffer (bug#20116).
5 (erc--buffer-p): New function, extracted from erc-buffer-filter.
6 (erc-buffer-filter): Use it.
7 (erc-with-all-buffers-of-server): Silence compile warning if the return
8 value is unused.
9 (erc-is-valid-nick-p, erc-common-server-suffixes, erc-get-arglist)
10 (erc-command-name, erc-popup-input-buffer): Use \` and \' to match
11 beg/end of string.
12
12015-03-03 Kelvin White <kwhite@gnu.org> 132015-03-03 Kelvin White <kwhite@gnu.org>
2 14
3 * erc.el: Add old version string back to file header for 15 * erc.el: Add old version string back to file header for
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index a84f9f07523..7e76a6def42 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1110,7 +1110,7 @@ which the local user typed."
1110 (define-key map "\C-a" 'erc-bol) 1110 (define-key map "\C-a" 'erc-bol)
1111 (define-key map [home] 'erc-bol) 1111 (define-key map [home] 'erc-bol)
1112 (define-key map "\C-c\C-a" 'erc-bol) 1112 (define-key map "\C-c\C-a" 'erc-bol)
1113 (define-key map "\C-c\C-b" 'erc-iswitchb) 1113 (define-key map "\C-c\C-b" 'erc-switch-to-buffer)
1114 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls) 1114 (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls)
1115 (define-key map "\C-c\C-d" 'erc-input-action) 1115 (define-key map "\C-c\C-d" 'erc-input-action)
1116 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse) 1116 (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse)
@@ -1647,6 +1647,14 @@ If PROC is not supplied, all processes are searched."
1647 (throw 'buffer (current-buffer))))) 1647 (throw 'buffer (current-buffer)))))
1648 proc)))) 1648 proc))))
1649 1649
1650(defun erc--buffer-p (buf predicate proc)
1651 (with-current-buffer buf
1652 (and (derived-mode-p 'erc-mode)
1653 (or (not proc)
1654 (eq proc erc-server-process))
1655 (funcall predicate)
1656 buf)))
1657
1650(defun erc-buffer-filter (predicate &optional proc) 1658(defun erc-buffer-filter (predicate &optional proc)
1651 "Return a list of `erc-mode' buffers matching certain criteria. 1659 "Return a list of `erc-mode' buffers matching certain criteria.
1652PREDICATE is a function executed with each buffer, if it returns t, that buffer 1660PREDICATE is a function executed with each buffer, if it returns t, that buffer
@@ -1659,12 +1667,7 @@ server connection, or nil which means all open connections."
1659 nil 1667 nil
1660 (mapcar (lambda (buf) 1668 (mapcar (lambda (buf)
1661 (when (buffer-live-p buf) 1669 (when (buffer-live-p buf)
1662 (with-current-buffer buf 1670 (erc--buffer-p buf predicate proc)))
1663 (and (eq major-mode 'erc-mode)
1664 (or (not proc)
1665 (eq proc erc-server-process))
1666 (funcall predicate)
1667 buf))))
1668 (buffer-list))))) 1671 (buffer-list)))))
1669 1672
1670(defun erc-buffer-list (&optional predicate proc) 1673(defun erc-buffer-list (&optional predicate proc)
@@ -1695,42 +1698,32 @@ nil."
1695 ,pro)))) 1698 ,pro))))
1696 ;; Silence the byte-compiler by binding the result of mapcar to 1699 ;; Silence the byte-compiler by binding the result of mapcar to
1697 ;; a variable. 1700 ;; a variable.
1701 (ignore res)
1698 res))) 1702 res)))
1699 1703
1700;; (iswitchb-mode) will autoload iswitchb.el 1704(define-obsolete-function-alias 'erc-iswitchb 'erc-switch-to-buffer "25.1")
1701(defvar iswitchb-temp-buflist) 1705(defun erc-switch-to-buffer (&optional arg)
1702(declare-function iswitchb-read-buffer "iswitchb" 1706 "Prompt for a ERC buffer to switch to.
1703 (prompt &optional default require-match start matches-set))
1704(defvar iswitchb-make-buflist-hook)
1705
1706(defun erc-iswitchb (&optional arg)
1707 "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to.
1708When invoked with prefix argument, use all erc buffers. Without prefix 1707When invoked with prefix argument, use all erc buffers. Without prefix
1709ARG, allow only buffers related to same session server. 1708ARG, allow only buffers related to same session server.
1710If `erc-track-mode' is in enabled, put the last element of 1709If `erc-track-mode' is in enabled, put the last element of
1711`erc-modified-channels-alist' in front of the buffer list. 1710`erc-modified-channels-alist' in front of the buffer list."
1712
1713Due to some yet unresolved reason, global function `iswitchb-mode'
1714needs to be active for this function to work."
1715 (interactive "P") 1711 (interactive "P")
1716 (let ((enabled (bound-and-true-p iswitchb-mode))) 1712 (switch-to-buffer
1717 (or enabled (iswitchb-mode 1)) 1713 (read-buffer "Switch to ERC buffer: "
1718 (unwind-protect 1714 (when (boundp 'erc-modified-channels-alist)
1719 (let ((iswitchb-make-buflist-hook 1715 (buffer-name (caar (last erc-modified-channels-alist))))
1720 (lambda () 1716 t
1721 (setq iswitchb-temp-buflist 1717 ;; Only allow ERC buffers in the same session.
1722 (mapcar 'buffer-name 1718 (let ((proc (unless arg erc-server-process)))
1723 (erc-buffer-list 1719 (lambda (bufname)
1724 nil 1720 (let ((buf (get-buffer bufname)))
1725 (when arg erc-server-process))))))) 1721 (when buf
1726 (switch-to-buffer 1722 (erc--buffer-p buf (lambda () t) proc)
1727 (iswitchb-read-buffer 1723 (with-current-buffer buf
1728 "Switch-to: " 1724 (and (derived-mode-p 'erc-mode)
1729 (if (boundp 'erc-modified-channels-alist) 1725 (or (null proc)
1730 (buffer-name (caar (last erc-modified-channels-alist))) 1726 (eq proc erc-server-process)))))))))))
1731 nil)
1732 t)))
1733 (or enabled (iswitchb-mode -1)))))
1734 1727
1735(defun erc-channel-list (proc) 1728(defun erc-channel-list (proc)
1736 "Return a list of channel buffers. 1729 "Return a list of channel buffers.
@@ -2189,7 +2182,7 @@ be invoked for the values of the other parameters."
2189Arguments are the same as for `erc'." 2182Arguments are the same as for `erc'."
2190 (interactive (erc-select-read-args)) 2183 (interactive (erc-select-read-args))
2191 (let ((erc-server-connect-function 'erc-open-tls-stream)) 2184 (let ((erc-server-connect-function 'erc-open-tls-stream))
2192 (apply 'erc r))) 2185 (apply #'erc r)))
2193 2186
2194(defun erc-open-tls-stream (name buffer host port) 2187(defun erc-open-tls-stream (name buffer host port)
2195 "Open an TLS stream to an IRC server. 2188 "Open an TLS stream to an IRC server.
@@ -2403,7 +2396,7 @@ If STRING is nil, the function does nothing."
2403 2396
2404(defun erc-is-valid-nick-p (nick) 2397(defun erc-is-valid-nick-p (nick)
2405 "Check if NICK is a valid IRC nickname." 2398 "Check if NICK is a valid IRC nickname."
2406 (string-match (concat "^" erc-valid-nick-regexp "$") nick)) 2399 (string-match (concat "\\`" erc-valid-nick-regexp "\\'") nick))
2407 2400
2408(defun erc-display-line (string &optional buffer) 2401(defun erc-display-line (string &optional buffer)
2409 "Display STRING in the ERC BUFFER. 2402 "Display STRING in the ERC BUFFER.
@@ -2602,9 +2595,9 @@ server within `erc-lurker-threshold-time'. See also
2602 erc-lurker-threshold-time)))) 2595 erc-lurker-threshold-time))))
2603 2596
2604(defcustom erc-common-server-suffixes 2597(defcustom erc-common-server-suffixes
2605 '(("openprojects.net$" . "OPN") 2598 '(("openprojects.net\\'" . "OPN")
2606 ("freenode.net$" . "freenode") 2599 ("freenode.net\\'" . "freenode")
2607 ("oftc.net$" . "OFTC")) 2600 ("oftc.net\\'" . "OFTC"))
2608 "Alist of common server name suffixes. 2601 "Alist of common server name suffixes.
2609This variable is used in mode-line display to save screen 2602This variable is used in mode-line display to save screen
2610real estate. Set it to nil if you want to avoid changing 2603real estate. Set it to nil if you want to avoid changing
@@ -2640,7 +2633,7 @@ ARGS, PARSED, and TYPE are used to format MSG sensibly.
2640 2633
2641See also `erc-format-message' and `erc-display-line'." 2634See also `erc-format-message' and `erc-display-line'."
2642 (let ((string (if (symbolp msg) 2635 (let ((string (if (symbolp msg)
2643 (apply 'erc-format-message msg args) 2636 (apply #'erc-format-message msg args)
2644 msg))) 2637 msg)))
2645 (setq string 2638 (setq string
2646 (cond 2639 (cond
@@ -2689,7 +2682,7 @@ See also `erc-server-send'."
2689(defun erc-get-arglist (fun) 2682(defun erc-get-arglist (fun)
2690 "Return the argument list of a function without the parens." 2683 "Return the argument list of a function without the parens."
2691 (let ((arglist (format "%S" (erc-function-arglist fun)))) 2684 (let ((arglist (format "%S" (erc-function-arglist fun))))
2692 (if (string-match "^(\\(.*\\))$" arglist) 2685 (if (string-match "\\`(\\(.*\\))\\'" arglist)
2693 (match-string 1 arglist) 2686 (match-string 1 arglist)
2694 arglist))) 2687 arglist)))
2695 2688
@@ -2705,7 +2698,7 @@ is not alive, nil otherwise."
2705 "For CMD being the function name of a ERC command, something like 2698 "For CMD being the function name of a ERC command, something like
2706erc-cmd-FOO, this returns a string /FOO." 2699erc-cmd-FOO, this returns a string /FOO."
2707 (let ((command-name (symbol-name cmd))) 2700 (let ((command-name (symbol-name cmd)))
2708 (if (string-match "^erc-cmd-\\(.*\\)$" command-name) 2701 (if (string-match "\\`erc-cmd-\\(.*\\)\\'" command-name)
2709 (concat "/" (match-string 1 command-name)) 2702 (concat "/" (match-string 1 command-name))
2710 command-name))) 2703 command-name)))
2711 2704
@@ -2796,7 +2789,7 @@ VALUE is computed by evaluating the rest of LINE in Lisp."
2796 (erc-display-line 2789 (erc-display-line
2797 (concat "Available user variables:\n" 2790 (concat "Available user variables:\n"
2798 (apply 2791 (apply
2799 'concat 2792 #'concat
2800 (mapcar 2793 (mapcar
2801 (lambda (var) 2794 (lambda (var)
2802 (let ((val (symbol-value var))) 2795 (let ((val (symbol-value var)))
@@ -3775,7 +3768,7 @@ Unban all currently banned users in the current channel."
3775 t))) 3768 t)))
3776 (erc-server-send (format "MODE %s b" chnl))))) 3769 (erc-server-send (format "MODE %s b" chnl)))))
3777 3770
3778 (t (let ((bans (mapcar 'cdr erc-channel-banlist))) 3771 (t (let ((bans (mapcar #'cdr erc-channel-banlist)))
3779 (when bans 3772 (when bans
3780 ;; Glob the bans into groups of three, and carry out the unban. 3773 ;; Glob the bans into groups of three, and carry out the unban.
3781 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@* 3774 ;; eg. /mode #foo -bbb a*!*@* b*!*@* c*!*@*
@@ -3930,7 +3923,7 @@ If `point' is at the beginning of a channel name, use that as default."
3930 (concat "Set topic of " (erc-default-target) ": ") 3923 (concat "Set topic of " (erc-default-target) ": ")
3931 (when erc-channel-topic 3924 (when erc-channel-topic
3932 (let ((ss (split-string erc-channel-topic "\C-o"))) 3925 (let ((ss (split-string erc-channel-topic "\C-o")))
3933 (cons (apply 'concat (if (cdr ss) (butlast ss) ss)) 3926 (cons (apply #'concat (if (cdr ss) (butlast ss) ss))
3934 0)))))) 3927 0))))))
3935 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter 3928 (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter
3936 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list))))) 3929 (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list)))))
@@ -5052,7 +5045,7 @@ arg-modes is a list of triples of the form:
5052 5045
5053 (MODE-CHAR ON/OFF ARGUMENT)." 5046 (MODE-CHAR ON/OFF ARGUMENT)."
5054 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string) 5047 (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string)
5055 (let ((chars (mapcar 'char-to-string (match-string 1 mode-string))) 5048 (let ((chars (mapcar #'char-to-string (match-string 1 mode-string)))
5056 ;; arguments in channel modes 5049 ;; arguments in channel modes
5057 (args-str (match-string 2 mode-string)) 5050 (args-str (match-string 2 mode-string))
5058 (args nil) 5051 (args nil)
@@ -5998,7 +5991,7 @@ Returns a list of the form (HIGH LOW), compatible with Emacs time format."
5998 (if (> minutes 0) 5991 (if (> minutes 0)
5999 `("%d minutes, %d seconds" ,minutes ,seconds) 5992 `("%d minutes, %d seconds" ,minutes ,seconds)
6000 `("%d seconds" ,seconds)))) 5993 `("%d seconds" ,seconds))))
6001 output (apply 'format format-args)) 5994 output (apply #'format format-args))
6002 ;; Change all "1 units" to "1 unit". 5995 ;; Change all "1 units" to "1 unit".
6003 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output) 5996 (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output)
6004 (setq output (erc-replace-match-subexpression-in-string 5997 (setq output (erc-replace-match-subexpression-in-string
@@ -6246,7 +6239,7 @@ if `erc-away' is non-nil."
6246 6239
6247(defun erc-format-channel-modes () 6240(defun erc-format-channel-modes ()
6248 "Return the current channel's modes." 6241 "Return the current channel's modes."
6249 (concat (apply 'concat 6242 (concat (apply #'concat
6250 "+" erc-channel-modes) 6243 "+" erc-channel-modes)
6251 (cond ((and erc-channel-user-limit erc-channel-key) 6244 (cond ((and erc-channel-user-limit erc-channel-key)
6252 (if erc-show-channel-key-p 6245 (if erc-show-channel-key-p
@@ -6438,7 +6431,7 @@ All windows are opened in the current frame."
6438 "Mode: " 6431 "Mode: "
6439 (mapcar (lambda (e) 6432 (mapcar (lambda (e)
6440 (list (symbol-name e))) 6433 (list (symbol-name e)))
6441 (apropos-internal "-mode$" 'commandp)) 6434 (apropos-internal "-mode\\'" 'commandp))
6442 nil t)))) 6435 nil t))))
6443 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name)) 6436 (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name))
6444 (funcall mode) 6437 (funcall mode)
@@ -6634,7 +6627,7 @@ See also `format-spec'."
6634 (error "No format spec for message %s" msg)) 6627 (error "No format spec for message %s" msg))
6635 (when (functionp entry) 6628 (when (functionp entry)
6636 (setq entry (apply entry args))) 6629 (setq entry (apply entry args)))
6637 (format-spec entry (apply 'format-spec-make args)))) 6630 (format-spec entry (apply #'format-spec-make args))))
6638 6631
6639;;; Various hook functions 6632;;; Various hook functions
6640 6633