Cestfait.ch

  • Home
  • Drupal
  • PHP 5
  • Jquery
  • Web Dev
  • Sys admin
  • Logiciels libres
  • Videos
  • Divers
  • Nous contacter
  • Mon c'est fait!
Home

Commenté-decommenté dans Emacs comme dans NotePad++

Submitted by FiG on Fri, 06/24/2011 - 16:02

Si vous étiez un ancien utilisateurs de NotePad++ et que maintenant vous êtes sous Emacs, mais que vous manquez terriblement la fonctionnalité du raccourci Ctrl+q pour commenté et decommenté une ligne de code. Ben voilà une petite fonction ELisp que j'ai fais pour remédier ceci.

Quand j'aurais un peu plus de temps peut-être je regarderais pour qu'on puisse faire sur une sélection de plusieurs ligne et non pas seulement la ligne courante.

Il vous reste juste a mettre le code suivant dans votre .emacs et de faire un M-x load-file ou restarter Emacs.

(defun toggle-comment()
  "Toggle the // style comments at the beginning of a line"
  (interactive)
  ; Save cursor position for later.
  (setq cursor (point))
  ; Setup comment string
  (setq comment-str "//")
  (setq comment-size (length comment-str))
  (move-beginning-of-line nil)
  ; Get current line from buffer and check if it is commented or not
  ; and apply or remove comment accordingly
  (setq line-of-code (buffer-substring (line-beginning-position) (line-end-position)))
  (if (not (equal (substring line-of-code 0 comment-size) comment-str))
      (progn 
        (setq line-of-code (concat comment-str line-of-code))
        (setq cursor (+ cursor comment-size))
        )
    (if (string= (substring line-of-code 0 comment-size) comment-str)
        (progn
          (setq line-of-code (substring line-of-code comment-size nil))
          (setq cursor (- cursor comment-size))
          )
      )
    )
  ; Overwrite old line with the newly commented one.
  (kill-line)
  (insert line-of-code)
  (newline)
  (goto-char cursor)
)
 
; Shortcut to call the function
(global-set-key "\C-q" 'toggle-comment)
0
Log in to vote
Your rating: None Average: 5 (1 vote)
  • Login or register to post comments
  • Share this
Tags:
  • emacs
  • Logiciels libres

2 reponses to "Commenté-decommenté dans Emacs comme dans NotePad++"

1. hahaha c'est juste! Il n'y a

Submitted by FiG on Tue, 06/28/2011 - 08:52.
hahaha c'est juste! Il n'y a pas assez de trucs sur Emacs! :P Je ne sais pas si tu doit ajouté de la conf pour le GeshiCode, mais il n'a pas l'air de voulour accepté du "Lisp" (voire meme du ELisp) :P ca fait un peu moche!
  • Login or register to post comments

2. yeah comme sa fait plaisir de

Submitted by Sir Squall on Sun, 06/26/2011 - 00:45.
yeah comme sa fait plaisir de pas etre le seul a poster des trucs sur emacs !!!
  • Login or register to post comments

User login

  • Create new account
  • Request new password
  • Sign in with Twitter

Translate

Sondage

Qu'elle version de drupal utilisez-vous ?

Submitted by Sir Squall on Tue, 04/10/2012 - 16:30
  • Login or register to post comments

Recent comments

  • Arf, je suis à l'armée!
    40 weeks 1 day ago
  • hahaha c'est juste! Il n'y a
    46 weeks 4 days ago
  • yeah comme sa fait plaisir de
    46 weeks 6 days ago
  • wouahou merciii :-) !
    50 weeks 5 days ago
  • J'y réponds aujourd'hui ici
    50 weeks 5 days ago
  • Salut, court article mais
    50 weeks 6 days ago
  • Oktoberfest power!!!
    1 year 3 weeks ago
  • yep je vais faire un petit
    1 year 5 weeks ago
  • It's regular approuved
    1 year 5 weeks ago
  • Pas d'exemple????
    1 year 5 weeks ago

Tags

cropping Divers drupal Drupal emacs firefox gmap Google Images Jquery jquery karmic koala La phrase du jour Lausanne Logiciels libres mysql PHP 5 RPG Sys admin ubuntu Web Dev yasnippet youtube Zend
more tags

Popular content

Today's:

  • Squall Beer Challenge '09
  • 8ème Forum eCulture - ERACOM - 4 septembre 2009
  • viportuguese-shop.com
  • Boxxy likes Drupal
  • Emacs Transparent
  • Grep afficher les lignes avant et après
  • Drupal Mollom sa rox!
  • Tinymce styles sorted
  • Bash scripting MySql
  • Mr. B

All time:

  • Drupal 7 effet avec les jquery.ui.dialog sur Drupal 6 !
  • Dries Keynote DrupalCon Paris 2009
  • Drupal bridge zend yeah !!
  • Jquery slider c'est de la bonne !!!
  • Drupal and Zend, form validate :)
  • Jquery JSON en _POST
  • [Drupal] Lightbox avec une gmap! yeah
  • [Drupal] Domain Access & memcache sa donne quoi ?
  • viportuguese-shop.com
  • Node Import et Taxonomy CSV

Last viewed:

  • Commande bash
  • Coder Night !!
  • Drupal and Zend, form validate :)
  • Nevillefacts
  • CloudFlare + Mollon
  • Cloudflare et Dropbox nommés Technology pioneers
  • Clip
  • illi(ci|s)te
  • Google Gadget
  • C'est fait en personne : Citation

Twitter

Latest Articles

Derniers liens publiés

  • Get the list of all enabled module
    http://drupal.org/node/440962
  • Cloudflare et Dropbox nommés Technology pioneers
    http://techcrunch.com/2011/09/01/cloudflare-dropbox-palantir-and-kickstarter-named-technology-pioneers-by-the-world-economic-forum/
  • Apprend le javascript en t'amusant
    http://www.codecademy.com
  • EPSACrop sur Drupal 7
    http://www.aswissidea.org/
  • Drupal solr attachement intégration
    http://tika.apache.org/

Pub

Google gadget

Add to Google

Facebook page

jiwa

all good song

Partenaires

Cyber Warfare

Drupal Factory

Dev Factory

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.