comparison lisp/net/rcirc.el @ 67014:d3d8e2bcfa98

(rcirc-mangle-text): Add bold face property without replacing existing properties. (rcirc-my-nick, rcirc-other-nick, rcirc-server) (rcirc-nick-in-message, rcirc-prompt): Use min-colors and remove tty specs. (rcirc-server-prefix, rcirc-server): New faces. (rcirc-url-regexp): Generate with rx macro. (rcirc-last-server-message-time): New variable. (rcirc-filter): Record time of last message. (rcirc-keepalive): Kill processes that did not send a message since the last ping. (rcirc-mode): Give rcirc-topic a local binding here.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 19 Nov 2005 13:11:36 +0000
parents 6cfb275aa300
children 7e0fcbf84eb8 69e184bbba16
comparison
equal deleted inserted replaced
67013:f263dd2ed52d 67014:d3d8e2bcfa98
255 255
256 256
257 (defvar rcirc-process-output nil) 257 (defvar rcirc-process-output nil)
258 (defvar rcirc-topic nil) 258 (defvar rcirc-topic nil)
259 (defvar rcirc-keepalive-timer nil) 259 (defvar rcirc-keepalive-timer nil)
260 (make-variable-buffer-local 'rcirc-topic) 260 (defvar rcirc-last-server-message-time nil)
261 (defun rcirc-connect (server port nick user-name full-name startup-channels) 261 (defun rcirc-connect (server port nick user-name full-name startup-channels)
262 "Return a connection to SERVER on PORT. 262 "Return a connection to SERVER on PORT.
263 263
264 User will identify using the values of NICK, USER-NAME and 264 User will identify using the values of NICK, USER-NAME and
265 FULL-NAME. The variable list of channel names in 265 FULL-NAME. The variable list of channel names in
288 (setq rcirc-nick nick) 288 (setq rcirc-nick nick)
289 (make-local-variable 'rcirc-process-output) 289 (make-local-variable 'rcirc-process-output)
290 (setq rcirc-process-output nil) 290 (setq rcirc-process-output nil)
291 (make-local-variable 'rcirc-startup-channels) 291 (make-local-variable 'rcirc-startup-channels)
292 (setq rcirc-startup-channels startup-channels) 292 (setq rcirc-startup-channels startup-channels)
293 (make-local-variable 'rcirc-last-server-message-time)
294 (setq rcirc-last-server-message-time (current-time))
293 295
294 ;; identify 296 ;; identify
295 (rcirc-send-string process (concat "NICK " nick)) 297 (rcirc-send-string process (concat "NICK " nick))
296 (rcirc-send-string process (concat "USER " user-name 298 (rcirc-send-string process (concat "USER " user-name
297 " hostname servername :" 299 " hostname servername :"
311 (declare (indent 1) (debug t)) 313 (declare (indent 1) (debug t))
312 `(with-current-buffer (process-buffer ,process) 314 `(with-current-buffer (process-buffer ,process)
313 ,@body)) 315 ,@body))
314 316
315 (defun rcirc-keepalive () 317 (defun rcirc-keepalive ()
316 "Send keep alive pings to active rcirc processes." 318 "Send keep alive pings to active rcirc processes.
319 Kill processes that have not received a server message since the
320 last ping."
317 (if (rcirc-process-list) 321 (if (rcirc-process-list)
318 (mapc (lambda (process) 322 (mapc (lambda (process)
319 (with-rcirc-process-buffer process 323 (with-rcirc-process-buffer process
320 (rcirc-send-string process (concat "PING " rcirc-server)))) 324 (if (> (cadr (time-since rcirc-last-server-message-time))
325 rcirc-keepalive-seconds)
326 (kill-process process)
327 (rcirc-send-string process (concat "PING " rcirc-server)))))
321 (rcirc-process-list)) 328 (rcirc-process-list))
322 (cancel-timer rcirc-keepalive-timer) 329 (cancel-timer rcirc-keepalive-timer)
323 (setq rcirc-keepalive-timer nil))) 330 (setq rcirc-keepalive-timer nil)))
324 331
325 (defvar rcirc-debug-buffer " *rcirc debug*") 332 (defvar rcirc-debug-buffer " *rcirc debug*")
378 Function is called with PROCESS COMMAND SENDER ARGS and LINE.") 385 Function is called with PROCESS COMMAND SENDER ARGS and LINE.")
379 (defun rcirc-filter (process output) 386 (defun rcirc-filter (process output)
380 "Called when PROCESS receives OUTPUT." 387 "Called when PROCESS receives OUTPUT."
381 (rcirc-debug process output) 388 (rcirc-debug process output)
382 (with-rcirc-process-buffer process 389 (with-rcirc-process-buffer process
390 (setq rcirc-last-server-message-time (current-time))
383 (setq rcirc-process-output (concat rcirc-process-output output)) 391 (setq rcirc-process-output (concat rcirc-process-output output))
384 (when (= (aref rcirc-process-output 392 (when (= (aref rcirc-process-output
385 (1- (length rcirc-process-output))) ?\n) 393 (1- (length rcirc-process-output))) ?\n)
386 (mapc (lambda (line) 394 (mapc (lambda (line)
387 (rcirc-process-server-response process line)) 395 (rcirc-process-server-response process line))
580 (setq rcirc-input-ring (make-ring rcirc-input-ring-size)) 588 (setq rcirc-input-ring (make-ring rcirc-input-ring-size))
581 (make-local-variable 'rcirc-process) 589 (make-local-variable 'rcirc-process)
582 (setq rcirc-process process) 590 (setq rcirc-process process)
583 (make-local-variable 'rcirc-target) 591 (make-local-variable 'rcirc-target)
584 (setq rcirc-target target) 592 (setq rcirc-target target)
593 (make-local-variable 'rcirc-topic)
594 (setq rcirc-topic nil)
585 595
586 (make-local-variable 'rcirc-short-buffer-name) 596 (make-local-variable 'rcirc-short-buffer-name)
587 (setq rcirc-short-buffer-name nil) 597 (setq rcirc-short-buffer-name nil)
588 (make-local-variable 'rcirc-urls) 598 (make-local-variable 'rcirc-urls)
589 (setq rcirc-urls nil) 599 (setq rcirc-urls nil)
848 (eq rcirc-process process)))) 858 (eq rcirc-process process))))
849 buffer 859 buffer
850 (process-buffer process)))) 860 (process-buffer process))))
851 861
852 (defun rcirc-format-response-string (process sender response target text) 862 (defun rcirc-format-response-string (process sender response target text)
853 (concat (when rcirc-time-format 863 (concat (rcirc-facify (format-time-string rcirc-time-format (current-time))
854 (format-time-string rcirc-time-format (current-time))) 864 'rcirc-timestamp)
855 (cond ((or (string= response "PRIVMSG") 865 (cond ((or (string= response "PRIVMSG")
856 (string= response "NOTICE") 866 (string= response "NOTICE")
857 (string= response "ACTION")) 867 (string= response "ACTION"))
858 (let (first middle end) 868 (let (first middle end)
859 (cond ((string= response "PRIVMSG") 869 (cond ((string= response "PRIVMSG")
878 (propertize (concat "!!! " text) 888 (propertize (concat "!!! " text)
879 'face 'font-lock-warning-face)) 889 'face 'font-lock-warning-face))
880 (t 890 (t
881 (rcirc-mangle-text 891 (rcirc-mangle-text
882 process 892 process
883 (rcirc-facify 893 (concat (rcirc-facify "*** " 'rcirc-server-prefix)
884 (concat "*** " 894 (rcirc-facify
885 (when (not (string= sender (rcirc-server process))) 895 (concat
886 (concat (rcirc-user-nick sender) " ")) 896 (when (not (string= sender (rcirc-server process)))
887 (when (zerop (string-to-number response)) 897 (concat (rcirc-user-nick sender) " "))
888 (concat response " ")) 898 (when (zerop (string-to-number response))
889 text) 899 (concat response " "))
890 'rcirc-server)))))) 900 text)
901 'rcirc-server)))))))
891 902
892 (defvar rcirc-activity-type nil) 903 (defvar rcirc-activity-type nil)
893 (make-variable-buffer-local 'rcirc-activity-type) 904 (make-variable-buffer-local 'rcirc-activity-type)
894 (defun rcirc-print (process sender response target text &optional activity) 905 (defun rcirc-print (process sender response target text &optional activity)
895 "Print TEXT in the buffer associated with TARGET. 906 "Print TEXT in the buffer associated with TARGET.
1444 1455
1445 (defun rcirc-facify (string face) 1456 (defun rcirc-facify (string face)
1446 "Return a copy of STRING with FACE property added." 1457 "Return a copy of STRING with FACE property added."
1447 (propertize (or string "") 'face face 'rear-nonsticky t)) 1458 (propertize (or string "") 'face face 'rear-nonsticky t))
1448 1459
1449 ;; shy grouping must be used within this regexp
1450 (defvar rcirc-url-regexp 1460 (defvar rcirc-url-regexp
1451 "\\b\\(?:\\(?:www\\.\\|\\(?:s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\ 1461 (rx word-boundary
1452 \\|wais\\|mailto\\):\\)\\(?://[-a-zA-Z0-9_.]+:[0-9]*\\)?\\(?:[-a-zA-Z0-9_=!?#$\ 1462 (or "www."
1453 @~`%&*+|\\/:;.,]\\|\\w\\)+\\(?:[-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)" 1463 (and (or "http" "https" "ftp" "file" "gopher" "news" "telnet" "wais"
1464 "mailto")
1465 "://"
1466 (1+ (char "a-zA-Z0-9_."))
1467 (optional ":" (1+ (char "0-9")))))
1468 (1+ (char "-a-zA-Z0-9_=!?#$\@~`%&*+|\\/:;.,"))
1469 (char "-a-zA-Z0-9_=!?#$\@~`%&*+|\\/:;"))
1454 "Regexp matching URL's. Set to nil to disable URL features in rcirc.") 1470 "Regexp matching URL's. Set to nil to disable URL features in rcirc.")
1455 1471
1456 (defun rcirc-browse-url (&optional arg) 1472 (defun rcirc-browse-url (&optional arg)
1457 "Prompt for url to browse based on urls in buffer." 1473 "Prompt for url to browse based on urls in buffer."
1458 (interactive) 1474 (interactive)
1496 1512
1497 (defun rcirc-mangle-text (process text) 1513 (defun rcirc-mangle-text (process text)
1498 "Return TEXT with properties added based on various patterns." 1514 "Return TEXT with properties added based on various patterns."
1499 ;; ^B 1515 ;; ^B
1500 (setq text 1516 (setq text
1501 (rcirc-map-regexp (lambda (start end string) 1517 (rcirc-map-regexp
1502 (add-text-properties 1518 (lambda (start end string)
1503 start end 1519 (let ((orig-face (get-text-property start 'face string)))
1504 (list 'face 'bold 'rear-nonsticky t) 1520 (add-text-properties
1505 string)) 1521 start end
1506 ".*?" 1522 (list 'face (if (listp orig-face)
1507 text)) 1523 (append orig-face
1508 (while (string-match "\\(.*\\)[]\\(.*\\)" text) ; deal with  1524 (list 'bold))
1525 (list orig-face 'bold))
1526 'rear-nonsticky t)
1527 string)))
1528 ".*?"
1529 text))
1530 ;; TODO: deal with ^_ and ^C colors sequences
1531 (while (string-match "\\(.*\\)[]\\(.*\\)" text)
1509 (setq text (concat (match-string 1 text) 1532 (setq text (concat (match-string 1 text)
1510 (match-string 2 text)))) 1533 (match-string 2 text))))
1511 ;; my nick 1534 ;; my nick
1512 (setq text 1535 (setq text
1513 (with-syntax-table rcirc-nick-syntax-table 1536 (with-syntax-table rcirc-nick-syntax-table
1525 (setq text 1548 (setq text
1526 (rcirc-map-regexp 1549 (rcirc-map-regexp
1527 (lambda (start end string) 1550 (lambda (start end string)
1528 (let ((orig-face (get-text-property start 'face string))) 1551 (let ((orig-face (get-text-property start 'face string)))
1529 (add-text-properties start end 1552 (add-text-properties start end
1530 (list 'face (list orig-face 'bold) 1553 (list 'face (if (listp orig-face)
1554 (append orig-face
1555 (list 'bold))
1556 (list orig-face 'bold))
1531 'rear-nonsticky t 1557 'rear-nonsticky t
1532 'mouse-face 'highlight 1558 'mouse-face 'highlight
1533 'keymap rcirc-browse-url-map) 1559 'keymap rcirc-browse-url-map)
1534 string)) 1560 string))
1535 (push (substring string start end) rcirc-urls)) 1561 (push (substring string start end) rcirc-urls))
1834 (defgroup rcirc-faces nil 1860 (defgroup rcirc-faces nil
1835 "Faces for rcirc." 1861 "Faces for rcirc."
1836 :group 'rcirc 1862 :group 'rcirc
1837 :group 'faces) 1863 :group 'faces)
1838 1864
1839 (defface rcirc-my-nick 1865 (defface rcirc-my-nick ; font-lock-function-name-face
1840 '((((type tty) (class color)) (:foreground "blue" :weight bold)) 1866 '((((class color) (min-colors 88) (background light)) (:foreground "Blue1"))
1841 (((class color) (background light)) (:foreground "Blue")) 1867 (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue"))
1842 (((class color) (background dark)) (:foreground "LightSkyBlue")) 1868 (((class color) (min-colors 16) (background light)) (:foreground "Blue"))
1843 (t (:inverse-video t :bold t))) 1869 (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue"))
1870 (((class color) (min-colors 8)) (:foreground "blue" :weight bold))
1871 (t (:inverse-video t :weight bold)))
1844 "The face used to highlight my messages." 1872 "The face used to highlight my messages."
1845 :group 'rcirc-faces) 1873 :group 'rcirc-faces)
1846 1874
1847 (defface rcirc-other-nick 1875 (defface rcirc-other-nick ; font-lock-variable-name-face
1848 '((((type tty) (class color)) (:foreground "yellow" :weight light)) 1876 '((((class grayscale) (background light))
1849 (((class grayscale) (background light)) 1877 (:foreground "Gray90" :weight bold :slant italic))
1850 (:foreground "Gray90" :bold t :italic t))
1851 (((class grayscale) (background dark)) 1878 (((class grayscale) (background dark))
1852 (:foreground "DimGray" :bold t :italic t)) 1879 (:foreground "DimGray" :weight bold :slant italic))
1853 (((class color) (background light)) (:foreground "DarkGoldenrod")) 1880 (((class color) (min-colors 88) (background light)) (:foreground "DarkGoldenrod"))
1854 (((class color) (background dark)) (:foreground "LightGoldenrod")) 1881 (((class color) (min-colors 88) (background dark)) (:foreground "LightGoldenrod"))
1855 (t (:bold t :italic t))) 1882 (((class color) (min-colors 16) (background light)) (:foreground "DarkGoldenrod"))
1883 (((class color) (min-colors 16) (background dark)) (:foreground "LightGoldenrod"))
1884 (((class color) (min-colors 8)) (:foreground "yellow" :weight light))
1885 (t (:weight bold :slant italic)))
1856 "The face used to highlight other messages." 1886 "The face used to highlight other messages."
1857 :group 'rcirc-faces) 1887 :group 'rcirc-faces)
1858 1888
1859 (defface rcirc-server 1889 (defface rcirc-server ; font-lock-comment-face
1860 '((((type tty pc) (class color) (background light)) (:foreground "red")) 1890 '((((class grayscale) (background light))
1861 (((type tty pc) (class color) (background dark)) (:foreground "red1")) 1891 (:foreground "DimGray" :weight bold :slant italic))
1862 (((class grayscale) (background light))
1863 (:foreground "DimGray" :bold t :italic t))
1864 (((class grayscale) (background dark)) 1892 (((class grayscale) (background dark))
1865 (:foreground "LightGray" :bold t :italic t)) 1893 (:foreground "LightGray" :weight bold :slant italic))
1866 (((class color) (background light)) (:foreground "gray40")) 1894 (((class color) (min-colors 88) (background light))
1867 (((class color) (background dark)) (:foreground "chocolate1")) 1895 (:foreground "Firebrick"))
1868 (t (:bold t :italic t))) 1896 (((class color) (min-colors 88) (background dark))
1897 (:foreground "chocolate1"))
1898 (((class color) (min-colors 16) (background light))
1899 (:foreground "red"))
1900 (((class color) (min-colors 16) (background dark))
1901 (:foreground "red1"))
1902 (((class color) (min-colors 8) (background light))
1903 )
1904 (((class color) (min-colors 8) (background dark))
1905 )
1906 (t (:weight bold :slant italic)))
1869 "The face used to highlight server messages." 1907 "The face used to highlight server messages."
1870 :group 'rcirc-faces) 1908 :group 'rcirc-faces)
1871 1909
1872 (defface rcirc-nick-in-message 1910 (defface rcirc-server-prefix ; font-lock-comment-delimiter-face
1873 '((((type tty) (class color)) (:foreground "cyan" :weight bold)) 1911 '((default :inherit font-lock-comment-face)
1874 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) 1912 (((class grayscale)))
1875 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) 1913 (((class color) (min-colors 16)))
1876 (((class color) (background light)) (:foreground "Purple")) 1914 (((class color) (min-colors 8) (background light))
1877 (((class color) (background dark)) (:foreground "Cyan")) 1915 :foreground "red")
1878 (t (:bold t))) 1916 (((class color) (min-colors 8) (background dark))
1917 :foreground "red1"))
1918 "The face used to highlight server prefixes."
1919 :group 'rcirc-faces)
1920
1921 (defface rcirc-timestamp
1922 '((t (:inherit default)))
1923 "The face used to highlight timestamps."
1924 :group 'rcirc-faces)
1925
1926 (defface rcirc-nick-in-message ; font-lock-keyword-face
1927 '((((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
1928 (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
1929 (((class color) (min-colors 88) (background light)) (:foreground "Purple"))
1930 (((class color) (min-colors 88) (background dark)) (:foreground "Cyan1"))
1931 (((class color) (min-colors 16) (background light)) (:foreground "Purple"))
1932 (((class color) (min-colors 16) (background dark)) (:foreground "Cyan"))
1933 (((class color) (min-colors 8)) (:foreground "cyan" :weight bold))
1934 (t (:weight bold)))
1879 "The face used to highlight instances of nick within messages." 1935 "The face used to highlight instances of nick within messages."
1880 :group 'rcirc-faces) 1936 :group 'rcirc-faces)
1881 1937
1882 (defface rcirc-prompt 1938 (defface rcirc-prompt ; comint-highlight-prompt
1883 '((((background dark)) (:foreground "cyan")) 1939 '((((min-colors 88) (background dark)) (:foreground "cyan1"))
1940 (((background dark)) (:foreground "cyan"))
1884 (t (:foreground "dark blue"))) 1941 (t (:foreground "dark blue")))
1885 "The face to use to highlight prompts." 1942 "The face to use to highlight prompts."
1886 :group 'rcirc-faces) 1943 :group 'rcirc-faces)
1887 1944
1888 (defface rcirc-mode-line-nick 1945 (defface rcirc-mode-line-nick