comparison lisp/net/rcirc.el @ 85854:41cfd60a7993

Ryan Yeske <rcyeske at gmail.com> (rcirc-last-quit-line, rcirc-last-line) (rcirc-elapsed-lines): New argument PROCESS. Update callers. (rcirc-print): Only update the line count when not marking the line as ommittable. (rcirc-log-write): Specify coding system when writing logfile. (rcirc-markup-fill): Make sure ellipsis does not cause line to wrap.
author Glenn Morris <rgm@gnu.org>
date Thu, 01 Nov 2007 03:51:47 +0000
parents bece18fa22d7
children e50a2e215441 880960b70474
comparison
equal deleted inserted replaced
85853:6d6c35a3f25a 85854:41cfd60a7993
1306 (defcustom rcirc-omit-threshold 100 1306 (defcustom rcirc-omit-threshold 100
1307 "Number of lines since last activity from a nick before `rcirc-omit-responses' are omitted." 1307 "Number of lines since last activity from a nick before `rcirc-omit-responses' are omitted."
1308 :type 'integer 1308 :type 'integer
1309 :group 'rcirc) 1309 :group 'rcirc)
1310 1310
1311 (defun rcirc-last-quit-line (nick target) 1311 (defun rcirc-last-quit-line (process nick target)
1312 "Return the line number where NICK left TARGET. 1312 "Return the line number where NICK left TARGET.
1313 Returns nil if the information is not recorded." 1313 Returns nil if the information is not recorded."
1314 (let ((chanbuf (rcirc-get-buffer (rcirc-buffer-process) target))) 1314 (let ((chanbuf (rcirc-get-buffer process target)))
1315 (when chanbuf 1315 (when chanbuf
1316 (cdr (assoc-string nick (with-current-buffer chanbuf 1316 (cdr (assoc-string nick (with-current-buffer chanbuf
1317 rcirc-recent-quit-alist)))))) 1317 rcirc-recent-quit-alist))))))
1318 1318
1319 (defun rcirc-last-line (nick target) 1319 (defun rcirc-last-line (process nick target)
1320 "Return the line from the last activity from NICK in TARGET." 1320 "Return the line from the last activity from NICK in TARGET."
1321 (let* ((chanbuf (rcirc-get-buffer (rcirc-buffer-process) target)) 1321 (let* ((chanbuf (rcirc-get-buffer process target))
1322 (line (or (cdr (assoc-string target 1322 (line (or (cdr (assoc-string target
1323 (gethash nick (with-rcirc-server-buffer 1323 (gethash nick (with-rcirc-server-buffer
1324 rcirc-nick-table)) t)) 1324 rcirc-nick-table)) t))
1325 (rcirc-last-quit-line nick target)))) 1325 (rcirc-last-quit-line process nick target))))
1326 (if line 1326 (if line
1327 line 1327 line
1328 ;;(message "line is nil for %s in %s" nick target) 1328 ;;(message "line is nil for %s in %s" nick target)
1329 nil))) 1329 nil)))
1330 1330
1331 (defun rcirc-elapsed-lines (nick target) 1331 (defun rcirc-elapsed-lines (process nick target)
1332 "Return the number of lines since activity from NICK in TARGET." 1332 "Return the number of lines since activity from NICK in TARGET."
1333 (let ((last-activity-line (rcirc-last-line nick target))) 1333 (let ((last-activity-line (rcirc-last-line process nick target)))
1334 (when (and last-activity-line 1334 (when (and last-activity-line
1335 (> last-activity-line 0)) 1335 (> last-activity-line 0))
1336 (- rcirc-current-line last-activity-line)))) 1336 (- rcirc-current-line last-activity-line))))
1337 1337
1338 (defvar rcirc-markup-text-functions 1338 (defvar rcirc-markup-text-functions
1339 '(rcirc-markup-attributes 1339 '(rcirc-markup-attributes
1340 rcirc-markup-my-nick 1340 rcirc-markup-my-nick
1341 rcirc-markup-urls 1341 rcirc-markup-urls
1342 rcirc-markup-keywords 1342 rcirc-markup-keywords
1343 rcirc-markup-bright-nicks 1343 rcirc-markup-bright-nicks)
1344 rcirc-markup-fill)
1345 1344
1346 "List of functions used to manipulate text before it is printed. 1345 "List of functions used to manipulate text before it is printed.
1347 1346
1348 Each function takes two arguments, SENDER, RESPONSE. The buffer 1347 Each function takes two arguments, SENDER, and RESPONSE. The
1349 is narrowed with the text to be printed and the point is at the 1348 buffer is narrowed with the text to be printed and the point is
1350 beginning of the `rcirc-text' propertized text.") 1349 at the beginning of the `rcirc-text' propertized text.")
1351 1350
1352 (defun rcirc-print (process sender response target text &optional activity) 1351 (defun rcirc-print (process sender response target text &optional activity)
1353 "Print TEXT in the buffer associated with TARGET. 1352 "Print TEXT in the buffer associated with TARGET.
1354 Format based on SENDER and RESPONSE. If ACTIVITY is non-nil, 1353 Format based on SENDER and RESPONSE. If ACTIVITY is non-nil,
1355 record activity." 1354 record activity."
1393 (fill-region fill-start 1392 (fill-region fill-start
1394 (1- (or (next-single-property-change fill-start 1393 (1- (or (next-single-property-change fill-start
1395 'rcirc-text) 1394 'rcirc-text)
1396 rcirc-prompt-end-marker))) 1395 rcirc-prompt-end-marker)))
1397 1396
1398 ;; increment the line count
1399 (setq rcirc-current-line (1+ rcirc-current-line))
1400
1401 ;; run markup functions 1397 ;; run markup functions
1402 (save-excursion 1398 (save-excursion
1403 (save-restriction 1399 (save-restriction
1404 (narrow-to-region start rcirc-prompt-start-marker) 1400 (narrow-to-region start rcirc-prompt-start-marker)
1405 (goto-char (or (next-single-property-change start 'rcirc-text) 1401 (goto-char (or (next-single-property-change start 'rcirc-text)
1413 1409
1414 (when rcirc-read-only-flag 1410 (when rcirc-read-only-flag
1415 (add-text-properties (point-min) (point-max) 1411 (add-text-properties (point-min) (point-max)
1416 '(read-only t front-sticky t)))) 1412 '(read-only t front-sticky t))))
1417 ;; make text omittable 1413 ;; make text omittable
1418 (let ((last-activity-lines (rcirc-elapsed-lines sender target))) 1414 (let ((last-activity-lines (rcirc-elapsed-lines process sender target)))
1419 (when (and (not (string= (rcirc-nick process) sender)) 1415 (if (and (not (string= (rcirc-nick process) sender))
1420 (member response rcirc-omit-responses) 1416 (member response rcirc-omit-responses)
1421 (or (not last-activity-lines) 1417 (or (not last-activity-lines)
1422 (< rcirc-omit-threshold last-activity-lines))) 1418 (< rcirc-omit-threshold last-activity-lines)))
1423 (put-text-property (1- start) (1- rcirc-prompt-start-marker) 1419 (put-text-property (1- start) (1- rcirc-prompt-start-marker)
1424 'invisible 'rcirc-omit))))) 1420 'invisible 'rcirc-omit)
1421 ;; otherwise increment the line count
1422 (setq rcirc-current-line (1+ rcirc-current-line))))))
1425 1423
1426 (set-marker-insertion-type rcirc-prompt-start-marker nil) 1424 (set-marker-insertion-type rcirc-prompt-start-marker nil)
1427 (set-marker-insertion-type rcirc-prompt-end-marker nil) 1425 (set-marker-insertion-type rcirc-prompt-end-marker nil)
1428 1426
1429 ;; truncate buffer if it is very long 1427 ;; truncate buffer if it is very long
1502 Log data is written to `rcirc-log-directory'." 1500 Log data is written to `rcirc-log-directory'."
1503 (make-directory rcirc-log-directory t) 1501 (make-directory rcirc-log-directory t)
1504 (dolist (cell rcirc-log-alist) 1502 (dolist (cell rcirc-log-alist)
1505 (with-temp-buffer 1503 (with-temp-buffer
1506 (insert (cdr cell)) 1504 (insert (cdr cell))
1507 (write-region (point-min) (point-max) 1505 (let ((coding-system-for-write 'utf-8))
1508 (concat rcirc-log-directory "/" (car cell)) 1506 (write-region (point-min) (point-max)
1509 t 'quiet))) 1507 (concat rcirc-log-directory "/" (car cell))
1508 t 'quiet))))
1510 (setq rcirc-log-alist nil)) 1509 (setq rcirc-log-alist nil))
1511 1510
1512 (defun rcirc-join-channels (process channels) 1511 (defun rcirc-join-channels (process channels)
1513 "Join CHANNELS." 1512 "Join CHANNELS."
1514 (save-window-excursion 1513 (save-window-excursion
1536 "Add CHANNEL to list associated with NICK. 1535 "Add CHANNEL to list associated with NICK.
1537 Update the associated linestamp if LINE is non-nil. 1536 Update the associated linestamp if LINE is non-nil.
1538 1537
1539 If the record doesn't exist, and LINE is nil, set the linestamp 1538 If the record doesn't exist, and LINE is nil, set the linestamp
1540 to zero." 1539 to zero."
1541 ;;(message "rcirc-put-nick-channel: %S %S %S" nick channel line)
1542 (let ((nick (rcirc-user-nick nick))) 1540 (let ((nick (rcirc-user-nick nick)))
1543 (with-rcirc-process-buffer process 1541 (with-rcirc-process-buffer process
1544 (let* ((chans (gethash nick rcirc-nick-table)) 1542 (let* ((chans (gethash nick rcirc-nick-table))
1545 (record (assoc-string channel chans t))) 1543 (record (assoc-string channel chans t)))
1546 (if record 1544 (if record
2238 (defun rcirc-markup-fill (sender response) 2236 (defun rcirc-markup-fill (sender response)
2239 (when (not (string= response "372")) ; /motd 2237 (when (not (string= response "372")) ; /motd
2240 (let ((fill-prefix 2238 (let ((fill-prefix
2241 (or rcirc-fill-prefix 2239 (or rcirc-fill-prefix
2242 (make-string (- (point) (line-beginning-position)) ?\s))) 2240 (make-string (- (point) (line-beginning-position)) ?\s)))
2243 (fill-column (cond ((eq rcirc-fill-column 'frame-width) 2241 (fill-column (- (cond ((eq rcirc-fill-column 'frame-width)
2244 (1- (frame-width))) 2242 (1- (frame-width)))
2245 (rcirc-fill-column 2243 (rcirc-fill-column
2246 rcirc-fill-column) 2244 rcirc-fill-column)
2247 (t fill-column)))) 2245 (t fill-column))
2246 ;; make sure ... doesn't cause line wrapping
2247 3)))
2248 (fill-region (point) (point-max) nil t)))) 2248 (fill-region (point) (point-max) nil t))))
2249 2249
2250 ;;; handlers 2250 ;;; handlers
2251 ;; these are called with the server PROCESS, the SENDER, which is a 2251 ;; these are called with the server PROCESS, the SENDER, which is a
2252 ;; server or a user, depending on the command, the ARGS, which is a 2252 ;; server or a user, depending on the command, the ARGS, which is a
2253 ;; list of strings, and the TEXT, which is the original server text, 2253 ;; list of strings, and the TEXT, which is the original server text,
2254 ;; verbatim 2254 ;; verbatim
2255 (defun rcirc-handler-001 (process sender args text) 2255 (defun rcirc-handler-001 (process sender args text)
2256 (rcirc-handler-generic process "001" sender args text) 2256 (rcirc-handler-generic process "001" sender args text)
2257 ;; set the real server name
2258 (with-rcirc-process-buffer process 2257 (with-rcirc-process-buffer process
2259 (setq rcirc-connecting nil) 2258 (setq rcirc-connecting nil)
2260 (rcirc-reschedule-timeout process) 2259 (rcirc-reschedule-timeout process)
2261 (setq rcirc-server-name sender) 2260 (setq rcirc-server-name sender)
2262 (setq rcirc-nick (car args)) 2261 (setq rcirc-nick (car args))
2301 (let ((channel (car args))) 2300 (let ((channel (car args)))
2302 (with-current-buffer (rcirc-get-buffer-create process channel) 2301 (with-current-buffer (rcirc-get-buffer-create process channel)
2303 ;; when recently rejoining, restore the linestamp 2302 ;; when recently rejoining, restore the linestamp
2304 (rcirc-put-nick-channel process sender channel 2303 (rcirc-put-nick-channel process sender channel
2305 (let ((last-activity-lines 2304 (let ((last-activity-lines
2306 (rcirc-elapsed-lines sender channel))) 2305 (rcirc-elapsed-lines process sender channel)))
2307 (when (and last-activity-lines 2306 (when (and last-activity-lines
2308 (< last-activity-lines rcirc-omit-threshold)) 2307 (< last-activity-lines rcirc-omit-threshold))
2309 (rcirc-last-line sender channel))))) 2308 (rcirc-last-line process sender channel)))))
2310 2309
2311 (rcirc-print process sender "JOIN" channel "") 2310 (rcirc-print process sender "JOIN" channel "")
2312 2311
2313 ;; print in private chat buffer if it exists 2312 ;; print in private chat buffer if it exists
2314 (when (rcirc-get-buffer (rcirc-buffer-process) sender) 2313 (when (rcirc-get-buffer (rcirc-buffer-process) sender)
2355 2354
2356 (rcirc-handler-PART-or-KICK process "KICK" channel sender nick reason))) 2355 (rcirc-handler-PART-or-KICK process "KICK" channel sender nick reason)))
2357 2356
2358 (defun rcirc-maybe-remember-nick-quit (process nick channel) 2357 (defun rcirc-maybe-remember-nick-quit (process nick channel)
2359 "Remember NICK as leaving CHANNEL if they recently spoke." 2358 "Remember NICK as leaving CHANNEL if they recently spoke."
2360 (let ((elapsed-lines (rcirc-elapsed-lines nick channel))) 2359 (let ((elapsed-lines (rcirc-elapsed-lines process nick channel)))
2361 (when (and elapsed-lines 2360 (when (and elapsed-lines
2362 (< elapsed-lines rcirc-omit-threshold)) 2361 (< elapsed-lines rcirc-omit-threshold))
2363 (let ((buffer (rcirc-get-buffer process channel))) 2362 (let ((buffer (rcirc-get-buffer process channel)))
2364 (when buffer 2363 (when buffer
2365 (with-current-buffer buffer 2364 (with-current-buffer buffer
2366 (let ((record (assoc-string nick rcirc-recent-quit-alist 2365 (let ((record (assoc-string nick rcirc-recent-quit-alist t))
2367 t)) 2366 (line (rcirc-last-line process nick channel)))
2368 (line (rcirc-last-line nick channel)))
2369 (if record 2367 (if record
2370 (setcdr record line) 2368 (setcdr record line)
2371 (setq rcirc-recent-quit-alist 2369 (setq rcirc-recent-quit-alist
2372 (cons (cons nick line) 2370 (cons (cons nick line)
2373 rcirc-recent-quit-alist)))))))))) 2371 rcirc-recent-quit-alist))))))))))