diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2015-03-16 14:49:01 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2015-03-16 14:49:01 -0400 |
commit | f925fc93bac41d7622d1af927e33b0e738ff55b0 (patch) | |
tree | e8635662256290a1662a299b66e32f6301535200 /lisp/erc/erc.el | |
parent | 43a847c02c3eb848cd0d55a4722bfe7f39b1112f (diff) | |
download | emacs-f925fc93bac41d7622d1af927e33b0e738ff55b0.tar.gz emacs-f925fc93bac41d7622d1af927e33b0e738ff55b0.tar.bz2 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/erc.el')
-rw-r--r-- | lisp/erc/erc.el | 99 |
1 files changed, 46 insertions, 53 deletions
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." (define-key map "\C-a" 'erc-bol) (define-key map [home] 'erc-bol) (define-key map "\C-c\C-a" 'erc-bol) - (define-key map "\C-c\C-b" 'erc-iswitchb) + (define-key map "\C-c\C-b" 'erc-switch-to-buffer) (define-key map "\C-c\C-c" 'erc-toggle-interpret-controls) (define-key map "\C-c\C-d" 'erc-input-action) (define-key map "\C-c\C-e" 'erc-toggle-ctcp-autoresponse) @@ -1647,6 +1647,14 @@ If PROC is not supplied, all processes are searched." (throw 'buffer (current-buffer))))) proc)))) +(defun erc--buffer-p (buf predicate proc) + (with-current-buffer buf + (and (derived-mode-p 'erc-mode) + (or (not proc) + (eq proc erc-server-process)) + (funcall predicate) + buf))) + (defun erc-buffer-filter (predicate &optional proc) "Return a list of `erc-mode' buffers matching certain criteria. PREDICATE 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." nil (mapcar (lambda (buf) (when (buffer-live-p buf) - (with-current-buffer buf - (and (eq major-mode 'erc-mode) - (or (not proc) - (eq proc erc-server-process)) - (funcall predicate) - buf)))) + (erc--buffer-p buf predicate proc))) (buffer-list))))) (defun erc-buffer-list (&optional predicate proc) @@ -1695,42 +1698,32 @@ nil." ,pro)))) ;; Silence the byte-compiler by binding the result of mapcar to ;; a variable. + (ignore res) res))) -;; (iswitchb-mode) will autoload iswitchb.el -(defvar iswitchb-temp-buflist) -(declare-function iswitchb-read-buffer "iswitchb" - (prompt &optional default require-match start matches-set)) -(defvar iswitchb-make-buflist-hook) - -(defun erc-iswitchb (&optional arg) - "Use `iswitchb-read-buffer' to prompt for a ERC buffer to switch to. +(define-obsolete-function-alias 'erc-iswitchb 'erc-switch-to-buffer "25.1") +(defun erc-switch-to-buffer (&optional arg) + "Prompt for a ERC buffer to switch to. When invoked with prefix argument, use all erc buffers. Without prefix ARG, allow only buffers related to same session server. If `erc-track-mode' is in enabled, put the last element of -`erc-modified-channels-alist' in front of the buffer list. - -Due to some yet unresolved reason, global function `iswitchb-mode' -needs to be active for this function to work." +`erc-modified-channels-alist' in front of the buffer list." (interactive "P") - (let ((enabled (bound-and-true-p iswitchb-mode))) - (or enabled (iswitchb-mode 1)) - (unwind-protect - (let ((iswitchb-make-buflist-hook - (lambda () - (setq iswitchb-temp-buflist - (mapcar 'buffer-name - (erc-buffer-list - nil - (when arg erc-server-process))))))) - (switch-to-buffer - (iswitchb-read-buffer - "Switch-to: " - (if (boundp 'erc-modified-channels-alist) - (buffer-name (caar (last erc-modified-channels-alist))) - nil) - t))) - (or enabled (iswitchb-mode -1))))) + (switch-to-buffer + (read-buffer "Switch to ERC buffer: " + (when (boundp 'erc-modified-channels-alist) + (buffer-name (caar (last erc-modified-channels-alist)))) + t + ;; Only allow ERC buffers in the same session. + (let ((proc (unless arg erc-server-process))) + (lambda (bufname) + (let ((buf (get-buffer bufname))) + (when buf + (erc--buffer-p buf (lambda () t) proc) + (with-current-buffer buf + (and (derived-mode-p 'erc-mode) + (or (null proc) + (eq proc erc-server-process))))))))))) (defun erc-channel-list (proc) "Return a list of channel buffers. @@ -2189,7 +2182,7 @@ be invoked for the values of the other parameters." Arguments are the same as for `erc'." (interactive (erc-select-read-args)) (let ((erc-server-connect-function 'erc-open-tls-stream)) - (apply 'erc r))) + (apply #'erc r))) (defun erc-open-tls-stream (name buffer host port) "Open an TLS stream to an IRC server. @@ -2403,7 +2396,7 @@ If STRING is nil, the function does nothing." (defun erc-is-valid-nick-p (nick) "Check if NICK is a valid IRC nickname." - (string-match (concat "^" erc-valid-nick-regexp "$") nick)) + (string-match (concat "\\`" erc-valid-nick-regexp "\\'") nick)) (defun erc-display-line (string &optional buffer) "Display STRING in the ERC BUFFER. @@ -2602,9 +2595,9 @@ server within `erc-lurker-threshold-time'. See also erc-lurker-threshold-time)))) (defcustom erc-common-server-suffixes - '(("openprojects.net$" . "OPN") - ("freenode.net$" . "freenode") - ("oftc.net$" . "OFTC")) + '(("openprojects.net\\'" . "OPN") + ("freenode.net\\'" . "freenode") + ("oftc.net\\'" . "OFTC")) "Alist of common server name suffixes. This variable is used in mode-line display to save screen real 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. See also `erc-format-message' and `erc-display-line'." (let ((string (if (symbolp msg) - (apply 'erc-format-message msg args) + (apply #'erc-format-message msg args) msg))) (setq string (cond @@ -2689,7 +2682,7 @@ See also `erc-server-send'." (defun erc-get-arglist (fun) "Return the argument list of a function without the parens." (let ((arglist (format "%S" (erc-function-arglist fun)))) - (if (string-match "^(\\(.*\\))$" arglist) + (if (string-match "\\`(\\(.*\\))\\'" arglist) (match-string 1 arglist) arglist))) @@ -2705,7 +2698,7 @@ is not alive, nil otherwise." "For CMD being the function name of a ERC command, something like erc-cmd-FOO, this returns a string /FOO." (let ((command-name (symbol-name cmd))) - (if (string-match "^erc-cmd-\\(.*\\)$" command-name) + (if (string-match "\\`erc-cmd-\\(.*\\)\\'" command-name) (concat "/" (match-string 1 command-name)) command-name))) @@ -2796,7 +2789,7 @@ VALUE is computed by evaluating the rest of LINE in Lisp." (erc-display-line (concat "Available user variables:\n" (apply - 'concat + #'concat (mapcar (lambda (var) (let ((val (symbol-value var))) @@ -3775,7 +3768,7 @@ Unban all currently banned users in the current channel." t))) (erc-server-send (format "MODE %s b" chnl))))) - (t (let ((bans (mapcar 'cdr erc-channel-banlist))) + (t (let ((bans (mapcar #'cdr erc-channel-banlist))) (when bans ;; Glob the bans into groups of three, and carry out the unban. ;; 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." (concat "Set topic of " (erc-default-target) ": ") (when erc-channel-topic (let ((ss (split-string erc-channel-topic "\C-o"))) - (cons (apply 'concat (if (cdr ss) (butlast ss) ss)) + (cons (apply #'concat (if (cdr ss) (butlast ss) ss)) 0)))))) (let ((topic-list (split-string topic "\C-o"))) ; strip off the topic setter (erc-cmd-TOPIC (concat (erc-default-target) " " (car topic-list))))) @@ -5052,7 +5045,7 @@ arg-modes is a list of triples of the form: (MODE-CHAR ON/OFF ARGUMENT)." (if (string-match "^\\s-*\\(\\S-+\\)\\(\\s-.*$\\|$\\)" mode-string) - (let ((chars (mapcar 'char-to-string (match-string 1 mode-string))) + (let ((chars (mapcar #'char-to-string (match-string 1 mode-string))) ;; arguments in channel modes (args-str (match-string 2 mode-string)) (args nil) @@ -5998,7 +5991,7 @@ Returns a list of the form (HIGH LOW), compatible with Emacs time format." (if (> minutes 0) `("%d minutes, %d seconds" ,minutes ,seconds) `("%d seconds" ,seconds)))) - output (apply 'format format-args)) + output (apply #'format format-args)) ;; Change all "1 units" to "1 unit". (while (string-match "\\([^0-9]\\|^\\)1 \\S-+\\(s\\)" output) (setq output (erc-replace-match-subexpression-in-string @@ -6246,7 +6239,7 @@ if `erc-away' is non-nil." (defun erc-format-channel-modes () "Return the current channel's modes." - (concat (apply 'concat + (concat (apply #'concat "+" erc-channel-modes) (cond ((and erc-channel-user-limit erc-channel-key) (if erc-show-channel-key-p @@ -6438,7 +6431,7 @@ All windows are opened in the current frame." "Mode: " (mapcar (lambda (e) (list (symbol-name e))) - (apropos-internal "-mode$" 'commandp)) + (apropos-internal "-mode\\'" 'commandp)) nil t)))) (pop-to-buffer (make-indirect-buffer (current-buffer) buffer-name)) (funcall mode) @@ -6634,7 +6627,7 @@ See also `format-spec'." (error "No format spec for message %s" msg)) (when (functionp entry) (setq entry (apply entry args))) - (format-spec entry (apply 'format-spec-make args)))) + (format-spec entry (apply #'format-spec-make args)))) ;;; Various hook functions |