net.el 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. ;;; net.el --- Browsing, mail, chat, network utils; w3m, wget, …
  2. ;; Copyright © 2014–2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. (require 'al-key)
  16. ;;; Global keys
  17. (al/bind-keys
  18. :prefix-map al/net-map
  19. :prefix-docstring "Map for net utils."
  20. :prefix "C-w"
  21. ("p" . al/ping)
  22. ("t" . al/traceroute)
  23. ("w" . wget)
  24. ("m" . al/url-wget-mp3))
  25. (al/bind-keys*
  26. :prefix-map al/web-search-map
  27. :prefix-docstring "Map for web-search commands and browsing URLs."
  28. :prefix "M-S"
  29. ("M-S" . web-search)
  30. ("d" . web-search-duckduckgo)
  31. ("Y" . web-search-yandex)
  32. ("y" . web-search-youtube)
  33. ("g" . web-search-github)
  34. ("G" . web-search-google)
  35. ("w e" . web-search-wikipedia-en)
  36. ("w r" . web-search-wikipedia-ru)
  37. ("W" . web-search-wiktionary-en)
  38. ("m" . web-search-multitran)
  39. ("a" . web-search-archwiki)
  40. ("A" . web-search-arch-package)
  41. ("e" . web-search-emacswiki)
  42. ("i" . web-search-ipduh)
  43. ("I" . web-search-ip-address)
  44. ("b" . web-search-debbugs)
  45. ("`" . web-search-ej)
  46. ("t" (w3m-browse-url "http://m.tv.yandex.ru/4"))
  47. ("l" . al/browse-irc-log)
  48. ("L" (al/browse-irc-log
  49. "guix"
  50. (format-time-string
  51. "%Y-%m-%d"
  52. (time-subtract (current-time)
  53. (seconds-to-time (* 24 60 60)))))))
  54. ;;; Browsing
  55. (with-eval-after-load 'w3m
  56. (setq
  57. w3m-confirm-leaving-secure-page nil
  58. w3m-use-title-buffer-name t ; don't duplicate title in the mode-line
  59. w3m-show-graphic-icons-in-mode-line nil
  60. w3m-modeline-image-status-on "🌼"
  61. w3m-modeline-status-off ""
  62. w3m-modeline-separator "")
  63. (defconst al/w3m-keys
  64. '("c" "u" "k" "M-s"
  65. ("<ctrl-m> a" (emms-add-url (w3m-anchor)))
  66. ("<ctrl-m> p" (emms-play-url (w3m-anchor)))
  67. ("i" . w3m-toggle-inline-image)
  68. ("I" . w3m-toggle-inline-images)
  69. ("b" . w3m-bookmark-view)
  70. ("y" . w3m-history)
  71. ("," . w3m-view-previous-page)
  72. ("p" . w3m-view-next-page)
  73. ("h" . al/w3m-previous-url)
  74. ("n" . al/w3m-next-url)
  75. ("<backtab>" . w3m-previous-form)
  76. ("<tab>" . w3m-next-form)
  77. ("R" . w3m-redisplay-this-page)
  78. ("g" . w3m-reload-this-page)
  79. ("j" . w3m-goto-url)
  80. ("." . w3m-previous-anchor)
  81. ("e" . w3m-next-anchor)
  82. ("o" . w3m-view-parent-page)
  83. ("O" (w3m-view-parent-page 0))
  84. ("U" . w3m-view-this-url-new-session)
  85. ("u 0" (browse-url w3m-current-url))
  86. ("u u" (browse-url (w3m-anchor)))
  87. ("u RET" (browse-url (w3m-anchor)))
  88. ("u v" (browse-url-default-browser
  89. (echo-msk-program-video-url (w3m-anchor))))
  90. ("c 0" . w3m-print-current-url)
  91. ("c RET" . w3m-print-this-url)
  92. ("s" . al/w3m-wget)
  93. ("w" . al/w3m-wget)
  94. ("C-w w" . al/w3m-wget)
  95. ("C-w m" (al/url-wget-mp3 (w3m-anchor)))
  96. ("C-c C-f" . w3m-next-buffer)
  97. ("C-c C-b" . w3m-previous-buffer))
  98. "Alist of auxiliary keys for `w3m-mode-map'.")
  99. (al/bind-keys-from-vars 'w3m-mode-map 'al/w3m-keys)
  100. (when (require 'al-w3m nil t)
  101. (al/w3m-bind-number-keys 'al/w3m-switch-to-buffer)
  102. (al/w3m-bind-number-keys 'al/w3m-kill-buffer "k")))
  103. (with-eval-after-load 'w3m-form
  104. (defconst al/w3m-form-keys
  105. '(("u" . w3m-form-input-select-set))
  106. "Alist of auxiliary keys for `w3m-form-input-select-keymap'.")
  107. (al/bind-keys-from-vars 'w3m-form-input-select-keymap
  108. '(al/lazy-moving-keys al/w3m-form-keys)))
  109. (with-eval-after-load 'al-w3m
  110. (setq
  111. al/w3m-search-link-depth 20
  112. al/w3m-search-re "[^[:alnum:]]*\\<%s\\>"))
  113. (with-eval-after-load 'browse-url
  114. (when (require 'al-browse-url nil t)
  115. (setq browse-url-browser-function 'al/choose-browser)
  116. (advice-add 'browse-url-default-browser
  117. :override 'al/browse-url-conkeror)))
  118. (with-eval-after-load 'al-browse-url
  119. (setcar (cl-find-if (lambda (spec)
  120. (string= "conkeror" (cadr spec)))
  121. al/browser-choices)
  122. '(?c ?u ?\C-m)))
  123. ;;; Mail, news, gnus
  124. (setq
  125. user-full-name "Alex Kost"
  126. user-mail-address (concat "alezost" '(?@ ?g) "mail" '(?.) "com"))
  127. (setq
  128. gnus-home-directory al/gnus-dir
  129. gnus-directory al/gnus-news-dir
  130. message-directory al/gnus-mail-dir
  131. ;; gnus-message-archive-group "sent"
  132. gnus-update-message-archive-method t)
  133. (setq mail-user-agent 'gnus-user-agent)
  134. (al/bind-keys
  135. :prefix-map al/gnus-map
  136. :prefix-docstring "Map for Gnus."
  137. :prefix "M-g"
  138. ("M-g" . al/gnus-switch-win-config)
  139. ("g" . al/gnus-switch-to-group-buffer)
  140. ("b" . al/gnus-switch-buffer)
  141. ("m" . gnus-msg-mail)
  142. ("n" . gnus-msg-mail))
  143. (with-eval-after-load 'nntp
  144. (setq nntp-connection-timeout 10))
  145. (with-eval-after-load 'gnus
  146. (require 'al-gnus nil t)
  147. (setq
  148. gnus-select-method '(nnml "")
  149. gnus-secondary-select-methods
  150. '((nnimap "gmail"
  151. (nnimap-address "imap.gmail.com")
  152. (nnimap-server-port 993)
  153. (nnimap-stream ssl))
  154. (nntp "gmane" (nntp-address "news.gmane.org"))))
  155. (setq
  156. gnus-group-buffer "*Gnus Groups*"
  157. gnus-group-mode-line-format "Gnus:"
  158. gnus-article-mode-line-format "Gnus: %m"
  159. gnus-summary-mode-line-format "Gnus: %p %Z"
  160. gnus-summary-line-format "%U%R%z %(%&user-date; %B%-3L %[%f%]%) %s\n"
  161. gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]"
  162. gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^User-Agent:"
  163. gnus-user-date-format-alist
  164. '(((gnus-seconds-today) . "Today %H:%M")
  165. ((+ 86400 (gnus-seconds-today)) . "Yest. %H:%M")
  166. ((* 86400 365) . "%d %b %H:%M")
  167. (t . "%Y-%m-%d "))
  168. gnus-subthread-sort-functions '(gnus-thread-sort-by-number
  169. gnus-thread-sort-by-date))
  170. (setq
  171. gnus-activate-level 3
  172. gnus-activate-foreign-newsgroups gnus-activate-level)
  173. (setq
  174. gnus-large-newsgroup 400
  175. gnus-treat-display-smileys nil
  176. mm-text-html-renderer 'gnus-w3m
  177. mm-inline-text-html-with-images t
  178. gnus-gcc-mark-as-read t)
  179. ;; Wrap text in gnus-article buffers by words.
  180. (add-hook 'gnus-article-mode-hook 'visual-line-mode)
  181. (setq gnus-article-truncate-lines nil)
  182. (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
  183. (al/add-hook-maybe 'dired-mode-hook 'turn-on-gnus-dired-mode))
  184. (with-eval-after-load 'gnus-srvr
  185. (defconst al/gnus-server-keys
  186. '(("u" . gnus-server-read-server)
  187. ("M-d" . gnus-server-edit-server))
  188. "Alist of auxiliary keys for `gnus-server-mode-map'.")
  189. (al/bind-keys-from-vars 'gnus-server-mode-map
  190. '(al/lazy-moving-keys al/gnus-server-keys)
  191. t)
  192. (al/bind-keys
  193. :map gnus-browse-mode-map
  194. ("." . gnus-browse-prev-group)
  195. ("e" . gnus-browse-next-group)
  196. ("u" . gnus-browse-select-group)
  197. ("U" . gnus-browse-unsubscribe-current-group)
  198. ("^" . gnus-browse-exit)))
  199. ;; `gnus-group-mode-map'/`gnus-summary-mode-map'/`gnus-article-mode-map'
  200. ;; are defined in "gnus.el" but are filled in
  201. ;; "gnus-group.el"/"gnus-sum.el"/"gnus-art.el".
  202. (with-eval-after-load 'gnus-group
  203. (setq gnus-group-goto-unread nil)
  204. (defconst al/gnus-group-keys
  205. '(("." . gnus-group-prev-group)
  206. ("e" . gnus-group-next-group)
  207. (">" . al/gnus-group-prev-unread-group)
  208. ("E" . al/gnus-group-next-unread-group)
  209. ("u" . gnus-group-read-group)
  210. ("U" . gnus-group-unsubscribe-current-group)
  211. ("m" . gnus-group-mark-group)
  212. ("z" . gnus-group-unmark-group)
  213. ("Z" . gnus-group-unmark-all-groups)
  214. ("M-U" . gnus-group-unsubscribe-group)
  215. ("H i" . gnus-info-find-node)
  216. ("C-k" . gnus-group-kill-group)
  217. ("C-t" . gnus-group-kill-region)
  218. ("H-u" . gnus-undo)
  219. ("<backtab>" . gnus-topic-unindent)
  220. ("M-." . gnus-topic-goto-previous-topic)
  221. ("M-e" . gnus-topic-goto-next-topic))
  222. "Alist of auxiliary keys for `gnus-group-mode-map'.")
  223. (al/bind-keys-from-vars 'gnus-group-mode-map 'al/gnus-group-keys)
  224. (add-hook 'gnus-group-mode-hook 'hl-line-mode))
  225. (with-eval-after-load 'gnus-sum
  226. (defvar al/ej-url-re "www\\.ej\\.ru.+id=\\([0-9]+\\)"
  227. "Regexp matching 'ej.ru' arcticles.")
  228. (setq
  229. gnus-sum-thread-tree-root "●─► "
  230. gnus-sum-thread-tree-false-root "○─► "
  231. gnus-sum-thread-tree-vertical "│"
  232. gnus-sum-thread-tree-leaf-with-other "├─► "
  233. gnus-sum-thread-tree-single-leaf "└─► "
  234. gnus-sum-thread-tree-indent " "
  235. gnus-sum-thread-tree-single-indent "■ "
  236. gnus-summary-newsgroup-prefix "⇒ "
  237. gnus-summary-to-prefix "→ ")
  238. (setq
  239. gnus-score-over-mark ?↑
  240. gnus-score-below-mark ?↓
  241. gnus-unseen-mark ?n
  242. gnus-read-mark ?✓
  243. gnus-killed-mark ?✗)
  244. (defconst al/gnus-summary-keys
  245. '("x" ; disable `gnus-summary-limit-to-unread'
  246. ("." . gnus-summary-prev-article)
  247. ("e" . gnus-summary-next-article)
  248. (">" . gnus-summary-prev-unread-article)
  249. ("E" . gnus-summary-next-unread-article)
  250. ("n" . gnus-summary-reply)
  251. ("m" . gnus-summary-mark-as-read-forward)
  252. ("r" . gnus-summary-mark-as-read-forward)
  253. ("z" . gnus-summary-clear-mark-forward)
  254. ("u" . gnus-summary-scroll-up)
  255. ("C-t" . gnus-summary-mark-region-as-read)
  256. ("h" . gnus-summary-toggle-header)
  257. ("b" . al/gnus-summary-toggle-display-buttonized)
  258. ("v" . gnus-article-view-part)
  259. ("V" . gnus-mime-view-all-parts)
  260. ("s" . gnus-article-save-part)
  261. ("i" . gnus-article-show-images)
  262. ("U" . al/gnus-summary-browse-link-url)
  263. ("a" . al/gnus-summary-emms-add-url)
  264. ("p" . al/gnus-summary-emms-play-url)
  265. ("<ctrl-m> a" . al/gnus-summary-emms-add-url)
  266. ("<ctrl-m> p" . al/gnus-summary-emms-play-url)
  267. ("w" (wget (al/gnus-summary-find-mm-url)))
  268. ("`" (web-search-ej (al/gnus-summary-find-url-by-re
  269. al/ej-url-re 1))))
  270. "Alist of auxiliary keys for `gnus-summary-mode'.")
  271. (al/bind-keys-from-vars 'gnus-summary-mode-map 'al/gnus-summary-keys)
  272. (al/add-hook-maybe 'gnus-summary-mode-hook
  273. '(hl-line-mode al/hbar-cursor-type)))
  274. (with-eval-after-load 'gnus-draft
  275. (defconst al/gnus-draft-keys
  276. '(("M-d" . gnus-draft-edit-message)
  277. "e")
  278. "Alist of auxiliary keys for `gnus-draft-mode-map'.")
  279. (al/bind-keys-from-vars 'gnus-draft-mode-map 'al/gnus-draft-keys))
  280. (with-eval-after-load 'gnus-art
  281. (setq
  282. gnus-unbuttonized-mime-types '("text/plain")
  283. gnus-blocked-images "githubusercontent"
  284. gnus-prompt-before-saving t
  285. gnus-default-article-saver 'gnus-summary-save-in-mail
  286. ;; `gnus-article-save-directory' is placed in "gnus.el" actually, but
  287. ;; I don't care.
  288. gnus-article-save-directory al/gnus-saved-dir)
  289. (defconst al/gnus-article-keys
  290. '("C-d")
  291. "Alist of auxiliary keys for `gnus-article-mode-map'.")
  292. (defconst al/gnus-url-button-keys
  293. '(("c" . gnus-article-copy-string))
  294. "Alist of auxiliary keys for `gnus-url-button-map'.")
  295. (defconst al/gnus-mime-button-keys
  296. '(("u" . gnus-mime-action-on-part)
  297. ("s" . gnus-mime-save-part)
  298. ("v" . gnus-mime-view-part-internally)
  299. ("V" . gnus-mime-view-part))
  300. "Alist of auxiliary keys for `gnus-mime-button-map'.")
  301. (al/bind-keys-from-vars 'gnus-article-mode-map
  302. '(al/widget-button-keys al/gnus-article-keys))
  303. (al/bind-keys-from-vars 'gnus-url-button-map
  304. '(al/widget-button-keys al/gnus-url-button-keys))
  305. (al/bind-keys-from-vars 'gnus-mime-button-map
  306. '(al/widget-button-keys al/gnus-mime-button-keys))
  307. (add-hook 'gnus-article-mode-hook
  308. (lambda () (setq-local widget-button-face nil))))
  309. (with-eval-after-load 'gnus-topic
  310. (setq
  311. gnus-topic-display-empty-topics nil
  312. gnus-topic-line-format "%i%(%{%n%}%) – %A %v\n")
  313. (al/bind-keys-from-vars 'gnus-topic-mode-map
  314. 'al/free-important-keys t))
  315. (with-eval-after-load 'gnus-dired
  316. (al/bind-keys
  317. :map gnus-dired-mode-map
  318. ("C-c a" . gnus-dired-attach)))
  319. (with-eval-after-load 'sendmail
  320. (setq
  321. send-mail-function 'smtpmail-send-it))
  322. (with-eval-after-load 'message
  323. (setq
  324. message-signature "Alex"
  325. message-send-mail-function 'smtpmail-send-it
  326. message-citation-line-function 'message-insert-formatted-citation-line
  327. message-citation-line-format "%N (%Y-%m-%d %H:%M %z) wrote:\n")
  328. (al/bind-keys-from-vars 'message-mode-map)
  329. (al/modify-syntax message-mode-syntax-table
  330. (?' "' ")
  331. (?\" "\" ")))
  332. (with-eval-after-load 'mml
  333. (defconst al/mml-keys
  334. '(("C-c a" . mml-attach-file)
  335. ("C-c f" . mml-attach-file)
  336. ("C-c b" . mml-attach-buffer)
  337. ("C-c P" . mml-preview))
  338. "Alist of auxiliary keys for `mml-mode-map'.")
  339. (al/bind-keys-from-vars 'mml-mode-map 'al/mml-keys))
  340. (with-eval-after-load 'smtpmail
  341. (setq
  342. smtpmail-smtp-server "smtp.gmail.com"
  343. smtpmail-smtp-service 587))
  344. (with-eval-after-load 'shr
  345. (al/bind-keys
  346. :map shr-map
  347. ("u" . shr-browse-url)
  348. ("c" . shr-copy-url)))
  349. (with-eval-after-load 'al-gnus
  350. (setq al/atom2rss-file (al/emacs-data-dir-file "atom2rss.xsl"))
  351. (advice-add 'mm-url-insert
  352. :after #'al/convert-atom-to-rss)
  353. (advice-add 'gnus-agent-make-mode-line-string
  354. :around #'al/gnus-agent-mode-line-string))
  355. (al/autoload "mu4e" mu4e)
  356. (with-eval-after-load 'mu4e
  357. (setq
  358. mu4e-maildir (expand-file-name "~/mail")
  359. mu4e~main-buffer-name "*mu4e-main*"))
  360. ;;; ERC
  361. (setq
  362. erc-modules
  363. '(autojoin
  364. button
  365. completion
  366. irccontrols
  367. keep-place
  368. list
  369. log
  370. match
  371. menu
  372. move-to-prompt
  373. netsplit
  374. networks
  375. noncommands
  376. notifications
  377. pcomplete
  378. readonly
  379. ring
  380. stamp
  381. track
  382. truncate)
  383. ;; Set `erc-autojoin-channels-alist' in the top level so that it can be
  384. ;; changed before loading ERC.
  385. erc-autojoin-channels-alist
  386. '(("freenode.net"
  387. "#emacs"
  388. "#erc"
  389. "#gnus"
  390. "#scheme"
  391. "#guile"
  392. "#guix"
  393. "#geiser"
  394. "#dunst"
  395. "#conkeror"
  396. "#stumpwm"
  397. "#openmw"
  398. "#org-mode"))
  399. erc-log-channels-directory (al/emacs-data-dir-file "erc-log"))
  400. (al/bind-keys*
  401. :prefix-map al/erc-map
  402. :prefix-docstring "Map for ERC."
  403. :prefix "M-c"
  404. ("M-c" . al/erc-track-switch-buffer)
  405. ("M-n" . al/erc-cycle)
  406. ("b" . al/erc-switch-buffer)
  407. ("M-s" . al/erc-switch-to-server-buffer)
  408. ;; Interactive erc - compute everything without prompting:
  409. ("c" (erc))
  410. ("R" . al/erc-server-buffer-rename)
  411. ("d" . al/erc-quit-server)
  412. ("j" . al/erc-join-channel)
  413. ("a" . al/erc-away)
  414. ("u" . al/erc-number-of-users)
  415. ("m" . erc-track-mode)
  416. ("n" . erc-notifications-mode)
  417. ("p" (erc-part-from-channel ""))
  418. ("e" (al/display-buffer "#emacs"))
  419. ("x" (al/display-buffer "#guix"))
  420. ("s" (al/display-buffer "#stumpwm"))
  421. ("M-z" (al/display-buffer "*status")))
  422. (with-eval-after-load 'erc
  423. (setq
  424. erc-server "chat.freenode.net"
  425. erc-port 7000
  426. erc-nick "alezost"
  427. erc-user-full-name user-full-name
  428. erc-server-reconnect-timeout 60
  429. erc-server-connect-function 'erc-open-tls-stream
  430. ;; erc-join-buffer 'bury
  431. erc-track-showcount t
  432. erc-prompt-for-password nil
  433. erc-hide-list '("JOIN" "QUIT")
  434. erc-track-exclude-types
  435. '("JOIN" "NICK" "PART" "QUIT" "MODE"
  436. "305" "306" ; away messages
  437. "324" ; channel modes
  438. "328"
  439. "329" ; channel was created on
  440. "332" ; welcome/topic messages
  441. "333" ; set topic
  442. "353" "477")
  443. erc-mode-line-format "%t"
  444. erc-mode-line-away-status-format " (AWAY %a %H:%M)"
  445. erc-header-line-format "%n%a on %S [%m,%l] %o"
  446. erc-timestamp-format-left "\n[%d %B %Y, %A]\n"
  447. erc-timestamp-intangible nil
  448. erc-keywords '("theme" "color" "dvorak" "sql" "guix" "game")
  449. erc-log-file-coding-system 'utf-8
  450. erc-paranoid t)
  451. (defun al/erc-quit-part-reason (&rest _)
  452. (concat "I live in GuixSD <http://www.gnu.org/s/guix>"
  453. " and Emacs <http://www.gnu.org/s/emacs>"))
  454. (setq
  455. erc-quit-reason 'al/erc-quit-part-reason
  456. erc-part-reason 'al/erc-quit-part-reason)
  457. (defconst al/erc-keys
  458. '(("<tab>" . pcomplete)
  459. ("M-." . erc-previous-command)
  460. ("M-e" . erc-next-command)
  461. ("C-a" . erc-bol)
  462. ("C-l" . al/erc-view-log-file)
  463. ("<s-kanji>" . al/recenter-end-of-buffer-top)
  464. ("C-H-3" . al/recenter-end-of-buffer-top))
  465. "Alist of auxiliary keys for erc mode.")
  466. (defun al/erc-bind-keys ()
  467. (al/bind-keys-from-vars 'erc-mode-map 'al/erc-keys))
  468. (al/add-hook-maybe 'erc-ring-mode-hook 'al/erc-bind-keys)
  469. (al/add-hook-maybe 'erc-mode-hook
  470. '(visual-line-mode abbrev-mode))
  471. ;; Do not consider "'" a part of a symbol, so that `symbol-at-point'
  472. ;; (used by `elisp-slime-nav' functions) returns a proper symbol.
  473. (al/modify-syntax erc-mode-syntax-table (?' "' "))
  474. (defun al/erc-channel-config ()
  475. "Define additional settings depending on a channel."
  476. (let ((buf (buffer-name (current-buffer))))
  477. (cond
  478. ((or (string-match "#scheme" buf)
  479. (string-match "#guile" buf))
  480. ;; Some hacks to make it possible to use guile process in erc
  481. ;; buffer.
  482. (setq-local geiser-impl--implementation 'guile)
  483. (setq-local geiser-eval--get-module-function
  484. (lambda (module) :f))
  485. (setq-local geiser-eval--geiser-procedure-function
  486. 'geiser-guile--geiser-procedure)
  487. (al/bind-local-keys-from-vars 'al/geiser-keys))
  488. ((string-match "#lisp" buf)
  489. (al/bind-local-keys-from-vars 'al/slime-keys))
  490. ((string-match "#stumpwm" buf)
  491. (setq-local slime-buffer-package :stumpwm)
  492. (al/bind-local-keys-from-vars 'al/slime-keys)))))
  493. (al/add-hook-maybe 'erc-join-hook 'al/erc-channel-config)
  494. (when (require 'al-erc nil t)
  495. (when (al/znc-running-p)
  496. (setq erc-server "localhost"
  497. erc-port 32456))
  498. (setq-default erc-enable-logging 'al/erc-log-all-but-some-buffers)
  499. (setq
  500. erc-insert-timestamp-function 'al/erc-insert-timestamp
  501. erc-view-log-timestamp-position 'left
  502. erc-generate-log-file-name-function
  503. 'al/erc-log-file-name-network-channel)
  504. (setq
  505. erc-ctcp-query-FINGER-hook '(al/erc-ctcp-query-FINGER)
  506. erc-ctcp-query-ECHO-hook '(al/erc-ctcp-query-ECHO)
  507. erc-ctcp-query-TIME-hook '(al/erc-ctcp-query-TIME)
  508. erc-ctcp-query-VERSION-hook '(al/erc-ctcp-query-VERSION))
  509. (al/add-hook-maybe 'erc-after-connect 'al/erc-ghost-maybe))
  510. (when (require 'sauron nil t)
  511. (setq sauron-watch-patterns
  512. (append sauron-watch-patterns
  513. '("theme" "color" "debpaste" "guix\\.el"
  514. "game" "ducpel" "sokoban")))
  515. (add-to-list 'sauron-modules 'sauron-erc))
  516. ;; ERC is loaded twice somehow (why??); so clear erc assoc of
  517. ;; `after-load-alist' to prevent the second loading of these settings.
  518. (setq after-load-alist
  519. (assq-delete-all 'erc after-load-alist)))
  520. (with-eval-after-load 'erc-desktop-notifications
  521. (defun al/play-erc-sound (&rest _)
  522. (require 'al-sound)
  523. (al/play-sound (al/sound-dir-file "chimes.wav")))
  524. (advice-add 'erc-notifications-notify :before #'al/play-erc-sound))
  525. (with-eval-after-load 'erc-button
  526. (al/bind-keys
  527. :map erc-button-keymap
  528. ("u" . erc-button-press-button)
  529. ("e" . al/next-link)
  530. ("." . al/previous-link)
  531. ("c" (kill-new (car (get-text-property (point) 'erc-data))))
  532. ("w" (wget (car (get-text-property (point) 'erc-data))))))
  533. (with-eval-after-load 'erc-list
  534. (al/bind-keys
  535. :map erc-list-menu-mode-map
  536. ("u" . erc-list-join)
  537. ("RET" . erc-list-join))
  538. (define-key erc-list-menu-sort-button-map
  539. [header-line mouse-2] 'erc-list-menu-sort-by-column))
  540. (with-eval-after-load 'al-erc
  541. (setq
  542. al/erc-log-excluded-regexps
  543. '("\\`#archlinux\\'" "\\`#emacs\\'" "\\`#freenode\\'" "\\`#znc\\'")
  544. al/erc-away-msg-list
  545. '("just away" "watching athletics" "watching darts"
  546. "eating" "i'm not ready to chat" "time to sleep")
  547. al/erc-channel-list
  548. '("#emacs" "#archlinux" "#archlinux-classroom" "#trivialand" "##latin"
  549. "#lisp" "#lispgames" "#git" "#github" "#netfilter" "#wesnoth"
  550. "#themanaworld" "##french" "##english" "##programming")))
  551. (al/autoload "erc-view-log" erc-view-log-mode)
  552. (al/with-check
  553. :var 'erc-log-channels-directory
  554. (push (cons (concat "\\`"
  555. (regexp-quote (expand-file-name
  556. erc-log-channels-directory)))
  557. 'erc-view-log-mode)
  558. auto-mode-alist))
  559. ;;; Debbugs
  560. (al/bind-keys
  561. :prefix-map al/debbugs-map
  562. :prefix-docstring "Map for debbugs."
  563. :prefix "M-B"
  564. ("M-B" . debbugs-gnu)
  565. ("n" . debbugs-gnu-bugs)
  566. ("b" (al/display-buffer "*Guix-Patches Bugs*"))
  567. ("s" . debbugs-gnu-search))
  568. (with-eval-after-load 'debbugs-gnu
  569. (setq debbugs-gnu-default-packages '("guix-patches"))
  570. (defconst al/debbugs-gnu-keys
  571. '(("u" . debbugs-gnu-select-report))
  572. "Alist of auxiliary keys for `debbugs-gnu-mode-map'.")
  573. (al/bind-keys-from-vars 'debbugs-gnu-mode-map 'al/debbugs-gnu-keys))
  574. ;;; Misc settings and packages
  575. (setq url-debug t)
  576. (with-eval-after-load 'url
  577. (setq url-configuration-directory (al/emacs-data-dir-file "url")))
  578. (with-eval-after-load 'wget
  579. (setq
  580. wget-debug-buffer "*wget-log*"
  581. wget-download-directory-filter 'wget-download-dir-filter-regexp
  582. wget-download-log-file (al/emacs-data-dir-file "emacs-wget.log")
  583. wget-download-directory
  584. `(("onlinetv" . ,(al/download-dir-file "onlinetv"))
  585. ("beatles" . ,(al/echo-download-dir-file "beatles"))
  586. ("classicrock" . ,(al/echo-download-dir-file "classicrock"))
  587. (,(regexp-quote "echo.msk.ru") . ,al/echo-download-dir)
  588. (,(regexp-opt '("ngenix.net/audio" "vgtrk.com/audio"))
  589. . ,(al/download-dir-file "mayak"))
  590. ("." . ,al/download-dir))))
  591. (with-eval-after-load 'mentor
  592. (setq mentor-rtorrent-url "scgi://127.0.0.1:5000"))
  593. (with-eval-after-load 'net-utils
  594. (setq ping-program-options '("-c" "3")))
  595. (with-eval-after-load 'al-net
  596. (setq
  597. al/net-hosts '("zeus" "hyperion" "192.168.1.1" "10.11.149.1"
  598. "10.10.0.1" "google.com" "ya.ru")
  599. al/router-log-path "~/docs/net/RT_G32.log/"))
  600. (al/bind-keys
  601. :prefix-map al/debpaste-map
  602. :prefix-docstring "Map for debpaste."
  603. :prefix "C-H-p"
  604. ("s" . debpaste-paste-region)
  605. ("r" . debpaste-display-paste)
  606. ("S" . debpaste-display-posted-info-in-buffer)
  607. ("R" . debpaste-display-received-info-in-buffer)
  608. ("d" . debpaste-delete-paste)
  609. ("q" . debpaste-quit-buffers)
  610. ("K" . debpaste-kill-all-buffers))
  611. (with-eval-after-load 'debpaste
  612. (setq
  613. debpaste-user-name "alezost"
  614. debpaste-expire-time (* 3 24 60 60))
  615. (add-to-list 'debpaste-domains "debpaste" t))
  616. (al/autoload "web-search"
  617. web-search-yandex
  618. web-search-youtube
  619. web-search-ipduh
  620. web-search-ip-address
  621. web-search-wikipedia-ru
  622. web-search-arch-package
  623. web-search-multitran
  624. web-search-ej)
  625. (with-eval-after-load 'web-search
  626. :config
  627. (web-search-add-engine
  628. 'ipduh "IPduh"
  629. "http://ipduh.com/apropos/?%s"
  630. 'web-search-clean-ip)
  631. (web-search-add-engine
  632. 'ip-address "IP address"
  633. "http://www.ip-address.org/lookup/ip-locator.php?track=%s"
  634. 'web-search-clean-ip)
  635. (web-search-add-engine
  636. 'yandex "Yandex"
  637. "http://yandex.ru/yandsearch?text=%s")
  638. (web-search-add-engine
  639. 'wikipedia-en "Wikipedia (english)"
  640. "http://en.wikipedia.org/w/index.php?search=%s")
  641. (web-search-add-engine
  642. 'wikipedia-ru "Wikipedia (russian)"
  643. "http://ru.wikipedia.org/w/index.php?search=%s")
  644. (web-search-add-engine
  645. 'youtube "Youtube"
  646. "http://www.youtube.com/results?search_query=%s&search=Search")
  647. (web-search-add-engine
  648. 'arch-package "Arch Packages"
  649. "https://www.archlinux.org/packages/?sort=&q=%s&maintainer=&flagged=")
  650. (web-search-add-engine
  651. 'multitran "Multitran"
  652. "http://www.multitran.ru/c/M.exe?CL=1&s=%s")
  653. (web-search-add-engine
  654. 'ej "ej.ru"
  655. "http://mvvc44tv.cmle.ru/?a=note&id=%s"))
  656. (al/bind-keys
  657. :prefix-map al/echo-msk-map
  658. :prefix-docstring "Map for echo-msk."
  659. :prefix "C-M-s-e"
  660. ("p" . echo-msk-program-task)
  661. ("s" . echo-msk-browse-schedule)
  662. ("a" . echo-msk-emms-play-online-audio)
  663. ("A" . echo-msk-browse-online-audio)
  664. ("v" . echo-msk-browse-online-video))
  665. (with-eval-after-load 'echo-msk
  666. (when (require 'dvorak-russian-computer nil t)
  667. (setq echo-msk-input-method "dvorak-russian-computer")))
  668. ;;; net.el ends here