Use lexical-binding and require cl-lib

* net/rcirc.el (rcirc, rcirc-handler-ctcp-KEEPALIVE)
(rcirc-handler-generic, rcirc-fill-paragraph)
(rcirc-format-response-string, rcirc-target-buffer)
(rcirc-last-line, rcirc-record-activity, rcirc-split-activity)
(rcirc-activity-string, rcirc-make-trees, rcirc-cmd-ctcp)
(rcirc-ctcp-sender-PING, rcirc-browse-url)
(rcirc-markup-timestamp, rcirc-markup-attributes)
(rcirc-markup-my-nick, rcirc-markup-urls)
(rcirc-markup-bright-nicks, rcirc-markup-fill)
(rcirc-check-auth-status, rcirc-handler-WALLOPS)
(rcirc-handler-JOIN, rcirc-handler-PART-or-KICK)
(rcirc-handler-PART, rcirc-handler-KICK, rcirc-handler-QUIT)
(rcirc-handler-NICK, rcirc-handler-PING, rcirc-handler-PONG)
(rcirc-handler-TOPIC, rcirc-handler-301, rcirc-handler-317)
(rcirc-handler-332, rcirc-handler-333, rcirc-handler-477)
(rcirc-handler-MODE, rcirc-handler-353, rcirc-handler-366)
(rcirc-authenticate, rcirc-handler-INVITE, rcirc-handler-ERROR)
(rcirc-handler-ctcp-VERSION, rcirc-handler-ctcp-TIME)
(rcirc-handler-CTCP-response): Fix unused arguments warnings and
use cl-lib.
This commit is contained in:
Leo Liu 2014-04-08 11:32:37 +08:00
parent 6f287c898a
commit dc0b0454fe
2 changed files with 93 additions and 71 deletions

View file

@ -1,3 +1,27 @@
2014-04-08 Leo Liu <sdl.web@gmail.com>
Use lexical-binding and require cl-lib.
* net/rcirc.el (rcirc, rcirc-handler-ctcp-KEEPALIVE)
(rcirc-handler-generic, rcirc-fill-paragraph)
(rcirc-format-response-string, rcirc-target-buffer)
(rcirc-last-line, rcirc-record-activity, rcirc-split-activity)
(rcirc-activity-string, rcirc-make-trees, rcirc-cmd-ctcp)
(rcirc-ctcp-sender-PING, rcirc-browse-url)
(rcirc-markup-timestamp, rcirc-markup-attributes)
(rcirc-markup-my-nick, rcirc-markup-urls)
(rcirc-markup-bright-nicks, rcirc-markup-fill)
(rcirc-check-auth-status, rcirc-handler-WALLOPS)
(rcirc-handler-JOIN, rcirc-handler-PART-or-KICK)
(rcirc-handler-PART, rcirc-handler-KICK, rcirc-handler-QUIT)
(rcirc-handler-NICK, rcirc-handler-PING, rcirc-handler-PONG)
(rcirc-handler-TOPIC, rcirc-handler-301, rcirc-handler-317)
(rcirc-handler-332, rcirc-handler-333, rcirc-handler-477)
(rcirc-handler-MODE, rcirc-handler-353, rcirc-handler-366)
(rcirc-authenticate, rcirc-handler-INVITE, rcirc-handler-ERROR)
(rcirc-handler-ctcp-VERSION, rcirc-handler-ctcp-TIME)
(rcirc-handler-CTCP-response): Fix unused arguments warnings and
use cl-lib.
2014-04-07 João Távora <joaotavora@gmail.com>
* elec-pair.el (electric-pair--syntax-ppss):

View file

@ -1,10 +1,10 @@
;;; rcirc.el --- default, simple IRC client.
;;; rcirc.el --- default, simple IRC client -*- lexical-binding: t; -*-
;; Copyright (C) 2005-2014 Free Software Foundation, Inc.
;; Author: Ryan Yeske <rcyeske@gmail.com>
;; Maintainers: Ryan Yeske <rcyeske@gmail.com>,
;; Deniz Dogan <deniz@dogan.se>
;; Leo Liu <sdl.web@gmail.com>
;; Keywords: comm
;; This file is part of GNU Emacs.
@ -43,9 +43,9 @@
;;; Code:
(require 'cl-lib)
(require 'ring)
(require 'time-date)
(eval-when-compile (require 'cl))
(defgroup rcirc nil
"Simple IRC client."
@ -489,7 +489,7 @@ If ARG is non-nil, instead prompt for connection parameters."
(when (string= server (process-name p))
(setq connected p)))
(if (not connected)
(condition-case e
(condition-case nil
(rcirc-connect server port nick user-name
full-name channels password encryption)
(quit (message "Quit connecting to %s" server)))
@ -629,7 +629,7 @@ last ping."
(cancel-timer rcirc-keepalive-timer))
(setq rcirc-keepalive-timer nil)))
(defun rcirc-handler-ctcp-KEEPALIVE (process target sender message)
(defun rcirc-handler-ctcp-KEEPALIVE (process _target _sender message)
(with-rcirc-process-buffer process
(setq header-line-format (format "%f" (- (rcirc-float-time)
(string-to-number message))))))
@ -752,7 +752,7 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
(defvar rcirc-responses-no-activity '("305" "306")
"Responses that don't trigger activity in the mode-line indicator.")
(defun rcirc-handler-generic (process response sender args text)
(defun rcirc-handler-generic (process response sender args _text)
"Generic server response handler."
(rcirc-print process sender response nil
(mapconcat 'identity (cdr args) " ")
@ -1222,13 +1222,13 @@ Create the buffer if it doesn't exist."
(ring-insert rcirc-input-ring input)
(setq rcirc-input-ring-index 0))))))
(defun rcirc-fill-paragraph (&optional arg)
(interactive "p")
(defun rcirc-fill-paragraph (&optional justify)
(interactive "P")
(when (> (point) rcirc-prompt-end-marker)
(save-restriction
(narrow-to-region rcirc-prompt-end-marker (point-max))
(let ((fill-column rcirc-max-message-length))
(fill-region (point-min) (point-max))))))
(fill-region (point-min) (point-max) justify)))))
(defun rcirc-process-input-line (line)
(if (string-match "^/\\([^ ]+\\) ?\\(.*\\)$" line)
@ -1393,9 +1393,9 @@ is found by looking up RESPONSE in `rcirc-response-formats'."
(rcirc-add-face start (match-beginning 0) face)
(setq start (match-beginning 0))
(replace-match
(case (aref (match-string 1) 0)
(cl-case (aref (match-string 1) 0)
(?f (setq face
(case (string-to-char (match-string 3))
(cl-case (string-to-char (match-string 3))
(?w 'font-lock-warning-face)
(?p 'rcirc-server-prefix)
(?s 'rcirc-server)
@ -1431,9 +1431,9 @@ is found by looking up RESPONSE in `rcirc-response-formats'."
(rcirc-add-face start (match-beginning 0) face))
(buffer-substring (point-min) (point-max))))
(defun rcirc-target-buffer (process sender response target text)
(defun rcirc-target-buffer (process sender response target _text)
"Return a buffer to print the server response."
(assert (not (bufferp target)))
(cl-assert (not (bufferp target)))
(with-rcirc-process-buffer process
(cond ((not target)
(rcirc-any-buffer process))
@ -1474,11 +1474,10 @@ Returns nil if the information is not recorded."
(defun rcirc-last-line (process nick target)
"Return the line from the last activity from NICK in TARGET."
(let* ((chanbuf (rcirc-get-buffer process target))
(line (or (cdr (assoc-string target
(gethash nick (with-rcirc-server-buffer
rcirc-nick-table)) t))
(rcirc-last-quit-line process nick target))))
(let ((line (or (cdr (assoc-string target
(gethash nick (with-rcirc-server-buffer
rcirc-nick-table)) t))
(rcirc-last-quit-line process nick target))))
(if line
line
;;(message "line is nil for %s in %s" nick target)
@ -1956,7 +1955,7 @@ activity. Only run if the buffer is not visible and
(let ((t1 (with-current-buffer b1 rcirc-last-post-time))
(t2 (with-current-buffer b2 rcirc-last-post-time)))
(time-less-p t2 t1)))))
(pushnew type rcirc-activity-types)
(cl-pushnew type rcirc-activity-types)
(unless (and (equal rcirc-activity old-activity)
(member type old-types))
(rcirc-update-activity-string)))))
@ -1977,13 +1976,13 @@ activity. Only run if the buffer is not visible and
(defun rcirc-split-activity (activity)
"Return a cons cell with ACTIVITY split into (lopri . hipri)."
(let (lopri hipri)
(dolist (buf rcirc-activity)
(dolist (buf activity)
(with-current-buffer buf
(if (and rcirc-low-priority-flag
(not (member 'nick rcirc-activity-types)))
(add-to-list 'lopri buf t)
(add-to-list 'hipri buf t))))
(cons lopri hipri)))
(push buf lopri)
(push buf hipri))))
(cons (nreverse lopri) (nreverse hipri))))
(defvar rcirc-update-activity-string-hook nil
"Hook run whenever the activity string is updated.")
@ -2015,7 +2014,7 @@ activity. Only run if the buffer is not visible and
(with-current-buffer b
(dolist (type rcirc-activity-types)
(rcirc-add-face 0 (length s)
(case type
(cl-case type
(nick 'rcirc-track-nick)
(keyword 'rcirc-track-keyword))
s)))
@ -2123,7 +2122,7 @@ activity. Only run if the buffer is not visible and
(when (and (listp x) (listp (cadr x)))
(setcdr x (if (> (length (cdr x)) 1)
(rcirc-make-trees (cdr x))
(setcdr x (list (cdadr x)))))))
(setcdr x (list (cl-cdadr x)))))))
alist)))
;;; /commands these are called with 3 args: PROCESS, TARGET, which is
@ -2281,7 +2280,7 @@ With a prefix arg, prompt for new topic."
(mapconcat 'identity (cdr arglist) " "))))
(rcirc-send-string process (concat "KICK " target " " argstring))))
(defun rcirc-cmd-ctcp (args &optional process target)
(defun rcirc-cmd-ctcp (args &optional process _target)
(if (string-match "^\\([^ ]+\\)\\s-+\\(.+\\)$" args)
(let* ((target (match-string 1 args))
(request (upcase (match-string 2 args)))
@ -2292,7 +2291,7 @@ With a prefix arg, prompt for new topic."
(rcirc-print process (rcirc-nick process) "ERROR" nil
"usage: /ctcp NICK REQUEST")))
(defun rcirc-ctcp-sender-PING (process target request)
(defun rcirc-ctcp-sender-PING (process target _request)
"Send a CTCP PING message to TARGET."
(let ((timestamp (format "%.0f" (rcirc-float-time))))
(rcirc-send-ctcp process target "PING" timestamp)))
@ -2412,21 +2411,20 @@ If ARG is given, opens the URL in a new browser window."
(lambda (x) (>= point (cdr x)))
rcirc-urls))
(completions (mapcar (lambda (x) (car x)) filtered))
(initial-input (caar filtered))
(history (mapcar (lambda (x) (car x)) (cdr filtered))))
(browse-url (completing-read "rcirc browse-url: "
completions nil nil initial-input 'history)
(defaults (mapcar (lambda (x) (car x)) filtered)))
(browse-url (completing-read "Rcirc browse-url: "
completions nil nil (car defaults) nil defaults)
arg)))
(defun rcirc-markup-timestamp (sender response)
(defun rcirc-markup-timestamp (_sender _response)
(goto-char (point-min))
(insert (rcirc-facify (format-time-string rcirc-time-format)
'rcirc-timestamp)))
(defun rcirc-markup-attributes (sender response)
(defun rcirc-markup-attributes (_sender _response)
(while (re-search-forward "\\([\C-b\C-_\C-v]\\).*?\\(\\1\\|\C-o\\)" nil t)
(rcirc-add-face (match-beginning 0) (match-end 0)
(case (char-after (match-beginning 1))
(cl-case (char-after (match-beginning 1))
(?\C-b 'bold)
(?\C-v 'italic)
(?\C-_ 'underline)))
@ -2440,7 +2438,7 @@ If ARG is given, opens the URL in a new browser window."
(while (re-search-forward "\C-o+" nil t)
(delete-region (match-beginning 0) (match-end 0))))
(defun rcirc-markup-my-nick (sender response)
(defun rcirc-markup-my-nick (_sender response)
(with-syntax-table rcirc-nick-syntax-table
(while (re-search-forward (concat "\\b"
(regexp-quote (rcirc-nick
@ -2454,7 +2452,7 @@ If ARG is given, opens the URL in a new browser window."
'rcirc-nick-in-message-full-line)
(rcirc-record-activity (current-buffer) 'nick)))))
(defun rcirc-markup-urls (sender response)
(defun rcirc-markup-urls (_sender _response)
(while (and rcirc-url-regexp ;; nil means disable URL catching
(re-search-forward rcirc-url-regexp nil t))
(let* ((start (match-beginning 0))
@ -2485,7 +2483,7 @@ If ARG is given, opens the URL in a new browser window."
(rcirc-add-face (match-beginning 0) (match-end 0) 'rcirc-keyword)
(rcirc-record-activity (current-buffer) 'keyword))))))
(defun rcirc-markup-bright-nicks (sender response)
(defun rcirc-markup-bright-nicks (_sender response)
(when (and rcirc-bright-nicks
(string= response "NAMES"))
(with-syntax-table rcirc-nick-syntax-table
@ -2493,7 +2491,7 @@ If ARG is given, opens the URL in a new browser window."
(rcirc-add-face (match-beginning 0) (match-end 0)
'rcirc-bright-nick)))))
(defun rcirc-markup-fill (sender response)
(defun rcirc-markup-fill (_sender response)
(when (not (string= response "372")) ; /motd
(let ((fill-prefix
(or rcirc-fill-prefix
@ -2574,7 +2572,7 @@ If ARG is given, opens the URL in a new browser window."
sender)))
message t))))
(defun rcirc-check-auth-status (process sender args text)
(defun rcirc-check-auth-status (process sender args _text)
"Check if the user just authenticated.
If authenticated, runs `rcirc-authenticated-hook' with PROCESS as
the only argument."
@ -2602,10 +2600,10 @@ the only argument."
(run-hook-with-args 'rcirc-authenticated-hook process)
(remove-hook 'rcirc-authenticated-hook 'rcirc-join-channels-post-auth t))))))
(defun rcirc-handler-WALLOPS (process sender args text)
(defun rcirc-handler-WALLOPS (process sender args _text)
(rcirc-print process sender "WALLOPS" sender (car args) t))
(defun rcirc-handler-JOIN (process sender args text)
(defun rcirc-handler-JOIN (process sender args _text)
(let ((channel (car args)))
(with-current-buffer (rcirc-get-buffer-create process channel)
;; when recently rejoining, restore the linestamp
@ -2626,7 +2624,7 @@ the only argument."
(rcirc-print process sender "JOIN" sender channel))))
;; PART and KICK are handled the same way
(defun rcirc-handler-PART-or-KICK (process response channel sender nick args)
(defun rcirc-handler-PART-or-KICK (process _response channel _sender nick _args)
(rcirc-ignore-update-automatic nick)
(if (not (string= nick (rcirc-nick process)))
;; this is someone else leaving
@ -2643,7 +2641,7 @@ the only argument."
(when buffer
(rcirc-disconnect-buffer buffer)))))
(defun rcirc-handler-PART (process sender args text)
(defun rcirc-handler-PART (process sender args _text)
(let* ((channel (car args))
(reason (cadr args))
(message (concat channel " " reason)))
@ -2654,10 +2652,10 @@ the only argument."
(rcirc-handler-PART-or-KICK process "PART" channel sender sender reason)))
(defun rcirc-handler-KICK (process sender args text)
(defun rcirc-handler-KICK (process sender args _text)
(let* ((channel (car args))
(nick (cadr args))
(reason (caddr args))
(reason (cl-caddr args))
(message (concat nick " " channel " " reason)))
(rcirc-print process sender "KICK" channel message t)
;; print in private chat buffer if it exists
@ -2682,7 +2680,7 @@ the only argument."
(cons (cons nick line)
rcirc-recent-quit-alist))))))))))
(defun rcirc-handler-QUIT (process sender args text)
(defun rcirc-handler-QUIT (process sender args _text)
(rcirc-ignore-update-automatic sender)
(mapc (lambda (channel)
;; broadcast quit message each channel
@ -2692,7 +2690,7 @@ the only argument."
(rcirc-nick-channels process sender))
(rcirc-nick-remove process sender))
(defun rcirc-handler-NICK (process sender args text)
(defun rcirc-handler-NICK (process sender args _text)
(let* ((old-nick sender)
(new-nick (car args))
(channels (rcirc-nick-channels process old-nick)))
@ -2723,25 +2721,25 @@ the only argument."
;; reauthenticate
(when rcirc-auto-authenticate-flag (rcirc-authenticate))))))
(defun rcirc-handler-PING (process sender args text)
(defun rcirc-handler-PING (process _sender args _text)
(rcirc-send-string process (concat "PONG :" (car args))))
(defun rcirc-handler-PONG (process sender args text)
(defun rcirc-handler-PONG (_process _sender _args _text)
;; do nothing
)
(defun rcirc-handler-TOPIC (process sender args text)
(defun rcirc-handler-TOPIC (process sender args _text)
(let ((topic (cadr args)))
(rcirc-print process sender "TOPIC" (car args) topic)
(with-current-buffer (rcirc-get-buffer process (car args))
(setq rcirc-topic topic))))
(defvar rcirc-nick-away-alist nil)
(defun rcirc-handler-301 (process sender args text)
(defun rcirc-handler-301 (process _sender args text)
"RPL_AWAY"
(let* ((nick (cadr args))
(rec (assoc-string nick rcirc-nick-away-alist))
(away-message (caddr args)))
(away-message (cl-caddr args)))
(when (or (not rec)
(not (string= (cdr rec) away-message)))
;; away message has changed
@ -2751,7 +2749,7 @@ the only argument."
(setq rcirc-nick-away-alist (cons (cons nick away-message)
rcirc-nick-away-alist))))))
(defun rcirc-handler-317 (process sender args text)
(defun rcirc-handler-317 (process sender args _text)
"RPL_WHOISIDLE"
(let* ((nick (nth 1 args))
(idle-secs (string-to-number (nth 2 args)))
@ -2765,31 +2763,31 @@ the only argument."
nick idle-string signon-string)))
(rcirc-print process sender "317" nil message t)))
(defun rcirc-handler-332 (process sender args text)
(defun rcirc-handler-332 (process _sender args _text)
"RPL_TOPIC"
(let ((buffer (or (rcirc-get-buffer process (cadr args))
(rcirc-get-temp-buffer-create process (cadr args)))))
(with-current-buffer buffer
(setq rcirc-topic (caddr args)))))
(setq rcirc-topic (cl-caddr args)))))
(defun rcirc-handler-333 (process sender args text)
(defun rcirc-handler-333 (process sender args _text)
"333 says who set the topic and when.
Not in rfc1459.txt"
(let ((buffer (or (rcirc-get-buffer process (cadr args))
(rcirc-get-temp-buffer-create process (cadr args)))))
(with-current-buffer buffer
(let ((setter (caddr args))
(let ((setter (cl-caddr args))
(time (current-time-string
(seconds-to-time
(string-to-number (cadddr args))))))
(string-to-number (cl-cadddr args))))))
(rcirc-print process sender "TOPIC" (cadr args)
(format "%s (%s on %s)" rcirc-topic setter time))))))
(defun rcirc-handler-477 (process sender args text)
(defun rcirc-handler-477 (process sender args _text)
"ERR_NOCHANMODES"
(rcirc-print process sender "477" (cadr args) (caddr args)))
(rcirc-print process sender "477" (cadr args) (cl-caddr args)))
(defun rcirc-handler-MODE (process sender args text)
(defun rcirc-handler-MODE (process sender args _text)
(let ((target (car args))
(msg (mapconcat 'identity (cdr args) " ")))
(rcirc-print process sender "MODE"
@ -2809,7 +2807,7 @@ Not in rfc1459.txt"
(let ((tmpnam (concat " " (downcase channel) "TMP" (process-name process))))
(get-buffer-create tmpnam)))
(defun rcirc-handler-353 (process sender args text)
(defun rcirc-handler-353 (process _sender args _text)
"RPL_NAMREPLY"
(let ((channel (nth 2 args))
(names (or (nth 3 args) "")))
@ -2822,7 +2820,7 @@ Not in rfc1459.txt"
(goto-char (point-max))
(insert (car (last args)) " "))))
(defun rcirc-handler-366 (process sender args text)
(defun rcirc-handler-366 (process sender args _text)
"RPL_ENDOFNAMES"
(let* ((channel (cadr args))
(buffer (rcirc-get-temp-buffer-create process channel)))
@ -2847,14 +2845,14 @@ Passwords are stored in `rcirc-authinfo' (which see)."
(dolist (i rcirc-authinfo)
(let ((process (rcirc-buffer-process))
(server (car i))
(nick (caddr i))
(nick (cl-caddr i))
(method (cadr i))
(args (cdddr i)))
(args (cl-cdddr i)))
(when (and (string-match server rcirc-server))
(if (and (memq method '(nickserv chanserv bitlbee))
(string-match nick rcirc-nick))
;; the following methods rely on the user's nickname.
(case method
(cl-case method
(nickserv
(rcirc-send-privmsg
process
@ -2878,10 +2876,10 @@ Passwords are stored in `rcirc-authinfo' (which see)."
"Q@CServe.quakenet.org"
(format "AUTH %s %s" nick (car args))))))))))
(defun rcirc-handler-INVITE (process sender args text)
(defun rcirc-handler-INVITE (process sender args _text)
(rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t))
(defun rcirc-handler-ERROR (process sender args text)
(defun rcirc-handler-ERROR (process sender args _text)
(rcirc-print process sender "ERROR" nil (mapconcat 'identity args " ")))
(defun rcirc-handler-CTCP (process target sender text)
@ -2899,7 +2897,7 @@ Passwords are stored in `rcirc-authinfo' (which see)."
(rcirc-print process sender "CTCP" target
(format "%s" text) t))))))
(defun rcirc-handler-ctcp-VERSION (process target sender args)
(defun rcirc-handler-ctcp-VERSION (process _target sender _args)
(rcirc-send-string process
(concat "NOTICE " sender
" :\C-aVERSION " rcirc-id-string
@ -2908,12 +2906,12 @@ Passwords are stored in `rcirc-authinfo' (which see)."
(defun rcirc-handler-ctcp-ACTION (process target sender args)
(rcirc-print process sender "ACTION" target args t))
(defun rcirc-handler-ctcp-TIME (process target sender args)
(defun rcirc-handler-ctcp-TIME (process _target sender _args)
(rcirc-send-string process
(concat "NOTICE " sender
" :\C-aTIME " (current-time-string) "\C-a")))
(defun rcirc-handler-CTCP-response (process target sender message)
(defun rcirc-handler-CTCP-response (process _target sender message)
(rcirc-print process sender "CTCP" nil message t))
(defgroup rcirc-faces nil