Humus numericus

Aller au contenu | Aller au menu | Aller à la recherche

R, Spip et autres

Mot-clé - emacs

Fil des billets

lundi 12 juillet 2010

Updated tangotango emacs color theme

EDIT : This post is now quite deprecated. Installation instructions and new versions are posted on the github project page.

I just updated my original ”tangotango” emacs color theme, based on the tango palette colors. I’ve tweaked some details and moved the source code to github. Here are updated installation instructions and screenshots :

Installation instructions

  1. Download and install the color-theme emacs package either via your linux distribution or via the source tarball
  2. Download and install color-theme-tangotango.el from github
  3. Make sure that both color-theme.el and color-theme-tangotango.el are in your load path

There are several ways to load the tangotango color theme from your .emacs, as documented on emacswiki. The way I currently use should work for a daemonized emacs and allows the selection of different themes for GUI or console based frames :

(require 'color-theme)
(setq color-theme-load-all-themes nil)

(require 'color-theme-tangotango)

;; select theme - first list element is for windowing system, second is for console/terminal
;; Source : http://www.emacswiki.org/emacs/ColorTheme#toc9
(setq color-theme-choices 
      '(color-theme-tangotango color-theme-tangotango))

;; default-start
(funcall (lambda (cols)
    	   (let ((color-theme-is-global nil))
    	     (eval 
    	      (append '(if (window-system))
    		      (mapcar (lambda (x) (cons x nil)) 
    			      cols)))))
    	 color-theme-choices)

;; test for each additional frame or console
(require 'cl)
(fset 'test-win-sys 
      (funcall (lambda (cols)
    		 (lexical-let ((cols cols))
    		   (lambda (frame)
    		     (let ((color-theme-is-global nil))
		       ;; must be current for local ctheme
		       (select-frame frame)
		       ;; test winsystem
		       (eval 
			(append '(if (window-system frame)) 
				(mapcar (lambda (x) (cons x nil)) 
					cols)))))))
    	       color-theme-choices ))
;; hook on after-make-frame-functions
(add-hook 'after-make-frame-functions 'test-win-sys)

(color-theme-tangotango)

Note that I also had to add a (color-theme-tangotango) line at the end of my .gnus file in order to apply the color theme to Gnus.

Screenshots

Here is a screenshot of the color theme with an emacs-lisp file :

tangotango_elisp.png

One with a Gnus summary and article buffers :

tangotango_gnus.png

And one with an org-mode buffer :

tangotango_org.png

mercredi 10 février 2010

Tangotango dark emacs color theme

UPDATE : This entry is deprecated ! Source code has been moved to Github and installation instructions have been rewritten.

I always have used the default Emacs color theme, with a white background. Recently I wanted to switch to a dark background but didn’t find a color scheme taht I’d like enough to use, so Is tarted to create one myself. In fact I started with the tango color theme on EmacsWiki, modified a bit, and added some faces to support gnus and org-mode as I use them a lot.

The result is a color theme named tangotango whose code is the following :

(defun color-theme-tangotango ()
  "A color theme based on Tango Palette."
  (interactive)
  (color-theme-install
   '(color-theme-tango
     ((background-color . "#2e3436")
      (background-mode . dark)
      (border-color . "#888a85")
      (cursor-color . "#fce94f")
      (foreground-color . "#eeeeec")
      (mouse-color . "#8ae234"))
     ((help-highlight-face . underline)
      (ibuffer-dired-buffer-face . font-lock-function-name-face)
      (ibuffer-help-buffer-face . font-lock-comment-face)
      (ibuffer-hidden-buffer-face . font-lock-warning-face)
      (ibuffer-occur-match-face . font-lock-warning-face)
      (ibuffer-read-only-buffer-face . font-lock-type-face)
      (ibuffer-special-buffer-face . font-lock-keyword-face)
      (ibuffer-title-face . font-lock-type-face))
     (highlight ((t (:background "brown4" :foreground nil))))
     (border ((t (:background "#888a85"))))
     (fringe ((t (:background "grey10"))))
     (mode-line ((t (:foreground "#bbbbbc" :background "#222222" :box (:line-width 1 :color nil :style released-button)))))
     (mode-line-inactive ((t (:foreground "#bbbbbc" :background "#555753"))))
     (mode-line-buffer-id ((t (:bold t :foreground "orange" :background nil))))
     (region ((t (:background "dark slate blue"))))
     (link ((t (:underline t :foreground "dodger blue"))))
     (custom-link ((t (:inherit 'link))))
     (match ((t (:bold t :background "#e9b96e" :foreground "#2e3436"))))
     (tool-tips ((t (:inherit 'variable-pitch :foreground "black" :background "lightyellow"))))
     (tooltip ((t (:inherit 'variable-pitch :foreground "black" :background "lightyellow"))))
     (bold ((t (:bold t :underline nil :background nil))))
     (italic ((t (:italic t :underline nil :background nil))))
     (font-lock-builtin-face ((t (:foreground "#729fcf"))))
     (font-lock-comment-face ((t (:foreground "#888a85"))))
     (font-lock-constant-face ((t (:foreground "#8ae234"))))
     (font-lock-doc-face ((t (:foreground "#888a85"))))
     (font-lock-keyword-face ((t (:foreground "#729fcf" :bold t))))
     (font-lock-string-face ((t (:foreground "#ad7fa8" :italic t))))
     (font-lock-type-face ((t (:foreground "#8ae234" :bold t))))
     (font-lock-variable-name-face ((t (:foreground "tomato"))))
     (font-lock-warning-face ((t (:bold t :foreground "#f57900"))))
     (font-lock-function-name-face ((t (:foreground "#edd400" :bold t))))
     (comint-highlight-input ((t (:italic t :bold t))))
     (comint-highlight-prompt ((t (:foreground "#8ae234"))))
     (isearch ((t (:background "#f57900" :foreground "#2e3436"))))
     (isearch-lazy-highlight-face ((t (:foreground "#2e3436" :background "#e9b96e"))))
     (show-paren-match-face ((t (:foreground "#2e3436" :background "#73d216"))))
     (show-paren-mismatch-face ((t (:background "#ad7fa8" :foreground "#2e3436"))))
     (minibuffer-prompt ((t (:foreground "#729fcf" :bold t))))
     (info-xref ((t (:foreground "#729fcf"))))
     (info-xref-visited ((t (:foreground "#ad7fa8"))))
     (diary-face ((t (:bold t :foreground "IndianRed"))))
     (eshell-ls-clutter-face ((t (:bold t :foreground "DimGray"))))
     (eshell-ls-executable-face ((t (:bold t :foreground "Coral"))))
     (eshell-ls-missing-face ((t (:bold t :foreground "black"))))
     (eshell-ls-special-face ((t (:bold t :foreground "Gold"))))
     (eshell-ls-symlink-face ((t (:bold t :foreground "White"))))
     (widget-button ((t (:bold t))))
     (widget-mouse-face ((t (:bold t :foreground "white" :background "brown4"))))
     (widget-field ((t (:foreground "orange" :background "gray30"))))
     (widget-single-line-field ((t (:foreground "orange" :background "gray30"))))
     (custom-group-tag ((t (:bold t :foreground "#edd400" :height 1.3))))
     (custom-variable-tag ((t (:bold t :foreground "#edd400" :height 1.1))))
     (custom-face-tag ((t (:bold t :foreground "#edd400" :height 1.1))))
     (custom-state-face ((t (:foreground "#729fcf"))))
     (custom-button  ((t (:box (:line-width 1 :style released-button) :background "grey50" :foreground "black"))))
     (custom-variable-button ((t (:inherit 'custom-button))))
     (custom-button-mouse  ((t (:inherit 'custom-button :background "grey60"))))
     (custom-button-unraised  ((t (:background "grey50" :foreground "black"))))
     (custom-button-mouse-unraised  ((t (:inherit 'custom-button-unraised :background "grey60"))))
     (custom-button-pressed  ((t (:inherit 'custom-button :box (:style pressed-button)))))
     (custom-button-mouse-pressed-unraised  ((t (:inherit 'custom-button-unraised :background "grey60"))))
     (custom-documentation ((t (:italic t))))
     (message-cited-text ((t (:foreground "#edd400")))) 
     (gnus-cite-face-1 ((t (:foreground "#ad7fa8"))))
     (gnus-cite-face-2 ((t (:foreground "sienna4"))))
     (gnus-cite-face-3 ((t (:foreground "khaki4"))))
     (gnus-cite-face-4 ((t (:foreground "PaleTurquoise4"))))
     (gnus-group-mail-1-empty-face ((t (:foreground "light cyan"))))
     (gnus-group-mail-1-face ((t (:bold t :foreground "light cyan"))))
     (gnus-group-mail-2-empty-face ((t (:foreground "turquoise"))))
     (gnus-group-mail-2-face ((t (:bold t :foreground "turquoise"))))
     (gnus-group-mail-3-empty-face ((t (:foreground "#729fcf"))))
     (gnus-group-mail-3-face ((t (:bold t :foreground "#edd400"))))
     (gnus-group-mail-low-empty-face ((t (:foreground "dodger blue"))))
     (gnus-group-mail-low-face ((t (:bold t :foreground "dodger blue"))))
     (gnus-group-news-1-empty-face ((t (:foreground "light cyan"))))
     (gnus-group-news-1-face ((t (:bold t :foreground "light cyan"))))
     (gnus-group-news-2-empty-face ((t (:foreground "turquoise"))))
     (gnus-group-news-2-face ((t (:bold t :foreground "turquoise"))))
     (gnus-group-news-3-empty-face ((t (:foreground "#729fcf"))))
     (gnus-group-news-3-face ((t (:bold t :foreground "#edd400"))))
     (gnus-group-news-low-empty-face ((t (:foreground "dodger blue"))))
     (gnus-group-news-low-face ((t (:bold t :foreground "dodger blue"))))
     (gnus-header-name-face ((t (:bold t :foreground "#729fcf"))))
     (gnus-header-from ((t (:bold t :foreground "#edd400"))))
     (gnus-header-subject ((t (:foreground "#edd400"))))
     (gnus-header-content ((t (:italic t :foreground "#8ae234"))))
     (gnus-header-newsgroups-face ((t (:italic t :bold t :foreground "LightSkyBlue3"))))
     (gnus-signature-face ((t (:italic t :foreground "dark grey"))))
     (gnus-summary-cancelled-face ((t (:background "black" :foreground "yellow"))))
     (gnus-summary-high-ancient-face ((t (:bold t :foreground "rotal blue"))))
     (gnus-summary-high-read-face ((t (:bold t :foreground "lime green"))))
     (gnus-summary-high-ticked-face ((t (:bold t :foreground "tomato"))))
     (gnus-summary-high-unread-face ((t (:bold t :foreground "white"))))
     (gnus-summary-low-ancient-face ((t (:italic t :foreground "lime green"))))
     (gnus-summary-low-read-face ((t (:italic t :foreground "royal blue"))))
     (gnus-summary-low-ticked-face ((t (:italic t :foreground "dark red"))))
     (gnus-summary-low-unread-face ((t (:italic t :foreground "white"))))
     (gnus-summary-normal-ancient-face ((t (:foreground "royal blue"))))
     (gnus-summary-normal-read-face ((t (:foreground "lime green"))))
     (gnus-summary-normal-ticked-face ((t (:foreground "indian red"))))
     (gnus-summary-normal-unread-face ((t (:foreground "white"))))
     (gnus-summary-selected ((t (:background "brown4" :foreground "white"))))
     (message-header-name-face ((t (:foreground "tomato"))))
     (message-header-newsgroups-face ((t (:italic t :bold t :foreground "LightSkyBlue3"))))
     (message-header-other-face ((t (:foreground "LightSkyBlue3"))))
     (message-header-xheader-face ((t (:foreground "DodgerBlue3"))))
     (message-header-subject ((t (:foreground "white"))))
     (message-header-to ((t (:foreground "white"))))
     (message-header-cc ((t (:foreground "white"))))
     (org-hide ((t (:foreground "#2e3436"))))
     (org-level-1 ((t (:bold t :foreground "dodger blue" :height 1.5))))
     (org-level-2 ((t (:bold t :foreground "#6ac214" :height 1.2))))
     (org-level-3 ((t (:bold t :foreground "#edd400" :height 1.1))))
     (org-level-4 ((t (:bold t :foreground "tomato" :height 1.0))))
     (org-date ((t (:underline t :foreground "magenta3"))))
     (org-footnote  ((t (:underline t :foreground "magenta3"))))
     (org-link ((t (:foreground "skyblue2" :background "#2e3436"))))
     (org-special-keyword ((t (:foreground "brown"))))
     (org-verbatim ((t (:foreground "#eeeeec" :underline t :slant italic))))
     (org-block ((t (:foreground "#bbbbbc"))))
     (org-quote ((t (:inherit org-block :slant italic))))
     (org-verse ((t (:inherit org-block :slant italic))))
     (org-todo ((t (:bold t :foreground "Red"))))
     (org-done ((t (:bold t :foreground "ForestGreen"))))
     (anything-header ((t (:bold t :background "grey15" :foreground "#edd400"))))
)))

Obviously you need to install and configure the color-theme Emacs extension to use it. You will find instructions on the dedicated EmacsWiki page. The setup I use is the following :

(require 'color-theme)
(color-theme-initialize)
(setq color-theme-is-global t)
(setq color-theme-is-cumulative t)
(setq color-theme-load-all-themes nil)

(color-theme-tangotango)

(add-hook 'message-mode-hook 'color-theme-tangotango)
(add-hook 'gnus-article-mode-hook 'color-theme-tangotango)

(add-hook 'after-make-frame-functions
	  (lambda (frame)
	    (set-variable 'color-theme-is-global nil)
	    (select-frame frame)
	    (if window-system
		(color-theme-tangotango)
	      (color-theme-tty-dark))))

Here is a screenshot of the color theme with an emacs-lisp file :

tangotango_elisp.png

One with a Gnus summary and article buffers :

tangotango_gnus.png

And one with an org-mode buffer :

tangotango_org.png

Feel free to give any feedback !

mercredi 5 avril 2006

Textile mode

Youpi, youpla, je viens de créer mon premier major mode pour Emacs. C'est un mode visant à faciliter l'écriture de document suivant la syntaxe de balisage Textile.

Pour l'instant il ne fait pas grand-chose, c'est à dire seulement de la coloration syntaxique, et il est en version vraiment alpha, pas plus testée que ça. N'hésitez pas à me faire remonter tout bug ou commentaire.

La dernière version du script peut être téléchargée là :

http://svn.nozav.org/scripts/elisp/textile-mode/textile-mode.el

Pour plus d'informations sur Textile, vous pouvez consulter :

samedi 7 janvier 2006

erc2html

Je viens de pondre un tout petit script en Ruby qui me permet de transformer un log de discussion IRC enregistré sous ERC (Emacs Relay Chat) en fichier HTML pour publication. Le script supprime les sauts de ligne superflus, supprime les messages serveur et colorise deux trois bricoles. C'est loin d'être parfait, mais si ça peut être utile à quelqu'un...

require "cgi"

str = IO.read("/home/julien/lautre_20060107.log.txt")

titre = "Titre de la page"
charset = "UTF-8"

head = <<EOL
<html>
<head>
<title>#{titre}</title>
<meta http-equiv="Content-Type" content="text/html; charset=#{charset}" />
<style type="text/css">
 * {font-family: monospace;}
 .nick {font-weight: bold; color: #A00;}
 .ref {font-style: italic; color: #090;}
 .timestamp {color: #AAA;}
 .me {color: #00B;}
</style>
</head>
<body>
<h1>#{titre}</h1>
<p>
EOL

foot = <<EOL
</p>
</body>
</html>
EOL

str.gsub!(/^ERC>.*$/n, "")
str.gsub!(/
\s+/n, " ")
str.gsub!(/[\d\d:\d\d]/) { |s| "
"+s+"
"}
str.gsub!(/\s+$/n, "")
str.gsub!(/^\*\*\* .*$/n, "")
5.times {str.gsub!(/
\s*
/n, "
")}

str = CGI::escapeHTML(str)
str.gsub!(/^&lt;.*?&gt;/n) {|s| '<span class="nick">'+s+'</span>'}
str.gsub!(/(<\/span>) (\w+\s?:)/n) {|s| $1+' <span class="ref">'+$2+'</span>'}
str.gsub!(/[\d\d:\d\d]/) { |s| '<span class="timestamp">'+s+'</span>'}
str.gsub!(/^\* .*$/n) {|s| '<span class="me">'+s+'</span>'}
str.gsub!(/
/, "<br />
")

str = head + str
str = str + foot

puts str

mardi 25 janvier 2005

Utiliser Jabber avec gaim ou emacs+erc+bitlbee derrière un firewall et/ou un proxy

Je viens d'installer ma machine sur le réseau de mon nouveau lieu de travail, et cela a été l'occasion de me repencher sur le sujet de "comment arriver à utiliser un client IM, en l'occurrence Jabber, à travers un firewall et un proxy http (pour discuter avec des collègues de travail sur des sujets strictement professionnels, cela va de soi).

Lorsqu'il n'y a qu'un firewall, c'est assez simple, car en général celui-ci autorise les connexions au port 80. Il suffit donc de se créer une adresse sur un serveur du type jabber80.com, qui tourne justement sur un port 80, et le tour est joué en utilisant Gaim.

Quand on a en plus un proxy http qui filtre les connexions, c'est un peu plus compliqué car les requêtes Jabber ne sont pas des requêtes http classiques. Le proxy risque donc de les bloquer, ce qui était mon cas. L'astuce réside alors à utiliser non pas le port 80, mais le port 443 (https), car les requêtes destinées à ce port ne sont pas filtrables par le proxy si celui-ci les accepte. Or, de nombreux serveurs Jabber tournent sur le port 443, dont toute la série des amessage (amessage.info...) et bien d'autres (jabberes.org, chrome.pl...). Là encore, avec Gaim, pas de problème, tout se paramètre lors de la création/modification du compte.

Jusque là, rien de très difficile et je ne fais que reprendre des infos présentes ici :

http://web.amessage.info/firewalled/

On va donc compliquer un peu : et si je veux utiliser non plus Gaim, mais un bon vieux emacs avec Erc, le tout sous Bitlbee (en fait, n'importe quel client IRC sous Bitlbee) ? A priori, suffit de faire pareil en commençant par indiquer les paramètres du proxy dans le fichier bitlbee.conf (le plus souvent dans /etc). Sauf qu'il n'est pas possible, en tous cas je n'ai pas trouvé l'option, de modifier le port par défaut pour la connexion aux serveurs Jabber dans les comptes sous Bitlbee. Gloups. Prenant mon courage à deux mains, j'ai donc décidé de tenter un gros hack bien sale et tout con mais qui a le mérite de marcher : modifier le port par défaut de connexion aux serveurs Jabber de 5222 et 5223 à 443 dans les sources de Bitlbee et recompiler la chose. Il va de soi que cette "astuce" au bulldozer ne pourra vous intéresser que si vous êtes sûr de ne vouloir vous connecter qu'à des ports 443 pour les serveurs Jabber de ce Bitlbee-là.

La manip sous Debian est assez simple. En premier lieu, il faut récupérer le paquet source avec un :

# apt-get source bitlbee

Il faut ensuite remplacer 5222 et 5223 par 443 dans les lignes suivantes du fichier protocols/jabber/jabber.c :

#define DEFAULT_PORT 5222
#define DEFAULT_PORT_SSL 5223

C'est fait ! Il n'y a plus qu'à reconstruire le package avec un petit dpkg-buildpackage, puis à l'installer avec un dpkg -i et le tour est joué.

Enfin, dernier intérêt, les connexions entre la machine faisant tourner Bitlbee et le serveur Jabber, si je ne me gourre, devraient être chiffrées. Ce qui n'est pas sans intérêt pour des conversations professionnelles hautement confidentielles...

Post-Scriptum : en fait non, je viens de vérifier pour le chiffrement des communications, et c'est à moitié vrai. Pour que ça marche sous Gaim, il faut cocher "forcer l'ancien SSL" dans la configuration du compte. Pour bitlbee, il faut modifier à nouveau le code source du fichier jabber.c, et plus précisément mettre "ssl=1" dans la portion de code suivante :

(...)
static void gjab_start(gjconn gjc)
{
   struct aim_user *user;
   int port = -1, ssl = 1;
(...)

jeudi 21 octobre 2004

Utiliser Mozilla Firefox pour ouvrir les liens sous Emacs/Gnus

La commande utilisée sous Emacs (et donc sous Gnus) pour ouvrir et afficher le contenu d'url contenues dans des documents ou des mails est à définir sous la forme d'une fonction à rattacher à la fonction browse-url-browser-function. Il existe un cetain nombre de fonctions par défaut, mais aucune pour Mozilla Firefox (en tous cas pour ma version d'Emacs, la 21.3.1). Grâce à EmacsWiki et à Google Groups, j'ai pu bricoler une fonction qui permet d'ouvrir le lien dans un nouveau tab si une instance de Firefox tourne déjà, et de lancer le navigateur sinon.

A priori ça fonctionne pour Firefox 0.9 et au-delà. Voici le code à rajouter dans votre .emacs :

(defun browse-url-firefox-new-tab (url &optional new-window)
  "Open URL in a new tab in Firefox."
  (interactive (browse-url-interactive-arg "URL: "))
  (let ((cmd (shell-command-to-string
              (concat "mozilla-firefox -a firefox -remote 'openURL("
                        url ",new-tab)' > /dev/null"))))
    (unless (string= "" cmd)
      (message "Starting Firefox...")
      (start-process (concat "firefox " url) nil "/bin/sh" "-c" 
               (concat "mozilla-firefox " url "|| true"))
      (message "Starting Firefox...done"))))
(setq browse-url-browser-function 'browse-url-firefox-new-tab)

Lire des fils RSS avec Gnus

Gnus (le lecteur de news mail et autres sous Emacs) sait tout faire, ça n'est pas nouveau. Il sait aussi lire des fils d'informations au format XML-RSS, mais la marche à suivre indiquée dans la documentation ne fonctionne pas chez moi. Celle-ci suggère de créer un nouveau groupe à l'aide des touches G R, mais chez moi ça débouche sur un message d'erreur :

No such newsgroup: nnrss:xxxxxxxxxx

Une autre méthode qui semble fonctionner est de créer le groupe dans un premier temps à l'aide de G m, de choisir un nom et indiquer nnrss comme 'From method'. Ensuite, à la première ouverture du nouveau groupe, Gnus vous demandera l'url du fichier RSS, et le tour est joué !