From 546d89e98fbd290469e7d414930a1f0430b43abc Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 18 Nov 2011 17:16:50 +0200 Subject: [PATCH] added basic support for Python programming and an extensive ERC config (to be refined) --- init.el | 2 + modules/prelude-erc.el | 178 ++++++++++++++++++++++++++++++++++++ modules/prelude-packages.el | 2 +- modules/prelude-python.el | 56 ++++++++++++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 modules/prelude-erc.el create mode 100644 modules/prelude-python.el diff --git a/init.el b/init.el index a557aee..07bcb70 100644 --- a/init.el +++ b/init.el @@ -76,11 +76,13 @@ by Prelude.") (require 'prelude-coffee) (require 'prelude-common-lisp) (require 'prelude-emacs-lisp) +(require 'prelude-erc) (require 'prelude-haskell) (require 'prelude-js) (require 'prelude-latex) (require 'prelude-markdown) (require 'prelude-perl) +(require 'prelude-python) (require 'prelude-ruby) (require 'prelude-scheme) (require 'prelude-xml) diff --git a/modules/prelude-erc.el b/modules/prelude-erc.el new file mode 100644 index 0000000..293daf9 --- /dev/null +++ b/modules/prelude-erc.el @@ -0,0 +1,178 @@ +;;; prelude-erc.el --- Emacs Prelude: ERC mode configuration. +;; +;; Copyright (c) 2011 Bozhidar Batsov +;; +;; Author: Bozhidar Batsov +;; URL: http://www.emacswiki.org/cgi-bin/wiki/Prelude +;; Version: 1.0.0 +;; Keywords: convenience + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Some basic configuration for ERC mode, which should make your +;; IRC experience a bit more pleasant. + +;;; License: + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License +;; as published by the Free Software Foundation; either version 3 +;; of the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Code: + +(require 'erc) +(require 'erc-log) +(require 'erc-notify) +(require 'erc-spelling) +(require 'erc-autoaway) + +;; Join the a couple of interesting channels whenever connecting to Freenode. +(setq erc-autojoin-channels-alist '(("freenode.net" + "#emacs" "#ruby" "#lisp"))) + +;; Interpret mIRC-style color commands in IRC chats +(setq erc-interpret-mirc-color t) + +;; The following are commented out by default, but users of other +;; non-Emacs IRC clients might find them useful. +;; Kill buffers for channels after /part +(setq erc-kill-buffer-on-part t) +;; Kill buffers for private queries after quitting the server +(setq erc-kill-queries-on-quit t) +;; Kill buffers for server messages after quitting the server +(setq erc-kill-server-buffer-on-quit t) + +;; open query buffers in the current window +(setq erc-query-display 'buffer) + +;; exclude boring stuff from tracking +(erc-track-mode t) +(setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE" + "324" "329" "332" "333" "353" "477")) + +;; logging +(setq erc-log-channels-directory "~/.erc/logs/") + +(if (not (file-exists-p erc-log-channels-directory)) + (mkdir erc-log-channels-directory t)) + +(setq erc-save-buffer-on-part t) +(defadvice save-buffers-kill-emacs (before save-logs (arg) activate) + (save-some-buffers t (lambda () (when (eq major-mode 'erc-mode) t)))) + +;; truncate long irc buffers +(erc-truncate-mode +1) + +;; share my real name +(setq erc-user-full-name "Bozhidar Batsov") + +;; enable spell checking +(erc-spelling-mode 1) +;; set different dictionaries by different servers/channels +;;(setq erc-spelling-dictionaries '(("#emacs" "american"))) + +;; TODO - replace this with use of notify.el +;; Notify my when someone mentions my nick. +(defun call-libnotify (matched-type nick msg) + (let* ((cmsg (split-string (clean-message msg))) + (nick (first (split-string nick "!"))) + (msg (mapconcat 'identity (rest cmsg) " "))) + (shell-command-to-string + (format "notify-send -u critical '%s says:' '%s'" nick msg)))) + +(when (eq system-type 'linux) + (add-hook 'erc-text-matched-hook 'call-libnotify)) + +(defvar erc-notify-nick-alist nil + "Alist of nicks and the last time they tried to trigger a +notification") + +(defvar erc-notify-timeout 10 + "Number of seconds that must elapse between notifications from +the same person.") + +(defun erc-notify-allowed-p (nick &optional delay) + "Return non-nil if a notification should be made for NICK. +If DELAY is specified, it will be the minimum time in seconds +that can occur between two notifications. The default is +`erc-notify-timeout'." + (unless delay (setq delay erc-notify-timeout)) + (let ((cur-time (time-to-seconds (current-time))) + (cur-assoc (assoc nick erc-notify-nick-alist)) + (last-time nil)) + (if cur-assoc + (progn + (setq last-time (cdr cur-assoc)) + (setcdr cur-assoc cur-time) + (> (abs (- cur-time last-time)) delay)) + (push (cons nick cur-time) erc-notify-nick-alist) + t))) + +;; private message notification +(defun erc-notify-on-private-msg (proc parsed) + (let ((nick (car (erc-parse-user (erc-response.sender parsed)))) + (target (car (erc-response.command-args parsed))) + (msg (erc-response.contents parsed))) + (when (and (erc-current-nick-p target) + (not (erc-is-message-ctcp-and-not-action-p msg)) + (erc-notify-allowed-p nick)) + (shell-command-to-string + (format "notify-send -u critical '%s says:' '%s'" nick msg)) + nil))) + +(add-hook 'erc-server-PRIVMSG-functions 'erc-notify-on-private-msg) + +;; autoaway setup +(setq erc-auto-discard-away t) +(setq erc-autoaway-idle-seconds 600) +(setq erc-autoaway-use-emacs-idle t) + +;; auto identify +(when (file-exists-p (expand-file-name "~/.ercpass")) + (load "~/.ercpass") + (require 'erc-services) + (erc-services-mode 1) + (setq erc-prompt-for-nickserv-password nil) + (setq erc-nickserv-passwords + `((freenode (("bozhidar" . ,bozhidar-pass))))) +) + +;; utf-8 always and forever +(setq erc-server-coding-system '(utf-8 . utf-8)) + +(defun start-irc () + "Connect to IRC." + (interactive) + (when (y-or-n-p "Do you want to start IRC? ") + (erc :server "irc.freenode.net" :port 6667 :nick "bozhidar"))) + +(defun filter-server-buffers () + (delq nil + (mapcar + (lambda (x) (and (erc-server-buffer-p x) x)) + (buffer-list)))) + +(defun stop-irc () + "Disconnects from all irc servers" + (interactive) + (dolist (buffer (filter-server-buffers)) + (message "Server buffer: %s" (buffer-name buffer)) + (with-current-buffer buffer + (erc-quit-server "Asta la vista")))) + +(provide 'prelude-erc) + +;;; prelude-erc.el ends here diff --git a/modules/prelude-packages.el b/modules/prelude-packages.el index ee56078..be5c4e3 100644 --- a/modules/prelude-packages.el +++ b/modules/prelude-packages.el @@ -45,7 +45,7 @@ (defvar prelude-packages '(auctex clojure-mode coffee-mode deft gist haml-mode haskell-mode magit markdown-mode paredit projectile - sass-mode scss-mode yaml-mode yari yasnippet) + python sass-mode scss-mode yaml-mode yari yasnippet) "A list of packages to ensure are installed at launch.") (dolist (p prelude-packages) diff --git a/modules/prelude-python.el b/modules/prelude-python.el new file mode 100644 index 0000000..ab1eff3 --- /dev/null +++ b/modules/prelude-python.el @@ -0,0 +1,56 @@ +;;; prelude-python.el --- Emacs Prelude: python.el configuration. +;; +;; Copyright (c) 2011 Bozhidar Batsov +;; +;; Author: Bozhidar Batsov +;; URL: http://www.emacswiki.org/cgi-bin/wiki/Prelude +;; Version: 1.0.0 +;; Keywords: convenience + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Some basic configuration for python.el (the latest and greatest +;; Python mode Emacs has to offer). + +;;; License: + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License +;; as published by the Free Software Foundation; either version 3 +;; of the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Code: + +;; customize +(defgroup python nil + "Emacs Prelude C programming support" + :group 'prelude) + +(defcustom prelude-enable-python-hook t + "Enable Prelude's default Python hook." + :type 'boolean + :group 'python) + +(require 'python) + +;; (defun prelude-python-coding-hook () +;; ) + +;; (when prelude-enable-python-hook +;; (add-hook 'python-mode-hook 'prelude-python-coding-hook)) + +(provide 'prelude-python) + +;;; prelude-python.el ends here