Skip to content

Instantly share code, notes, and snippets.

@Natim
Last active October 9, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natim/3447584 to your computer and use it in GitHub Desktop.
Save Natim/3447584 to your computer and use it in GitHub Desktop.
Emacs configuration
;; Ici on parle UTF-8
(set-language-environment "UTF-8")
;; Fichier de Customize
(setq custom-file "~/.emacs-custom.el")
(load custom-file)
;; On supprime ce qui est inutile (Barre d'outils, scroll)
(menu-bar-mode nil)
(tool-bar-mode -1)
(scroll-bar-mode nil)
;; On affiche le numéro de colonne
(column-number-mode t)
;; On fais des retours lignes automatiques même avec des fenêtres côtes à côtes
(setq truncate-partial-width-windows nil)
;; Plus de ring-bell
(setq ring-bell-function 'ignore)
;; Affichage de l'heure
(display-time-mode t)
;; Ctrl-c r pour afficher le rechercher/remplacer
(global-set-key "\C-cr" 'replace-string)
;; Ctrl-c n pour aller au buffer suivant
(global-set-key "\C-cn" 'bury-buffer)
;; Ctrl-c w pour quitter le buffer courant
(global-set-key "\C-cw" 'kill-this-buffer)
;; On indente avec des espaces en python
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode nil)))
(add-hook 'js-mode-hook
(lambda ()
(setq indent-tabs-mode nil)))
;; Change la valeur de l'indentation.
(setq c-basic-offset 4)
(setq-default tab-width 4)
(setq js-indent-level 2)
;; N'affiche pas le buffer de démarrage.
(setq inhibit-startup-message t)
(put 'downcase-region 'disabled nil)
;; Undo
(global-set-key [(control z)] `undo)
;; Laisser le curseur en place lors du défilement avec la molette
(setq scroll-preserve-screen-position t)
;; Mise en surbrillance des lignes sélectionnées et écrasement de ces
;; dernières lorsqu'on saisit du texte dans la foulée.
(progn
(delete-selection-mode 1)
(transient-mark-mode 1)
)
; Supprimer les fichiers de sauvegarde en quittant.
; (vous savez, ces fameux fichiers dont le nom se termine par « ~ »)
(setq make-backup-files nil)
(defun justify-paragraph ()
"Fill and justify current paragraph."
(interactive)
(fill-paragraph 1)
)
(global-set-key "\C-j" 'justify-paragraph)
;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Also highlight parens
(show-paren-mode 1)
(defadvice show-paren-function (after show-matching-paren-offscreen
activate))
;; Type d'indentation
(setq c-default-style "bsd")
;; Type de caractères de fin de ligne
(set-buffer-file-coding-system 'unix 't)
(fset 'coding
[?# ? kp-subtract kp-multiply kp-subtract ? ?c ?o ?d ?i ?n ?g ?: ? ?u ?t ?f kp-subtract kp-8 ? kp-subtract kp-multiply kp-subtract return])
(require 'whitespace)
(setq whitespace-style '(lines-tail))
(global-whitespace-mode t)
(add-hook 'html-mode-hook
(lambda()
(setq sgml-basic-offset 4)
(setq indent-tabs-mode nil)))
(add-to-list 'load-path "~/.emacs.d/vendor")
(add-hook 'find-file-hook 'flymake-find-file-hook)
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pycheckers" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(load-library "flymake-cursor")
(add-to-list 'load-path "~/git/jshint-mode")
(require 'flymake-jshint)
(add-hook 'javascript-mode-hook
(lambda () (flymake-mode t)))
(put 'upcase-region 'disabled nil)
;;; flymake-cursor.el --- displays flymake error msg in minibuffer after delay
;;
;; Author : ??
;; origin : http://paste.lisp.org/display/60617,1/raw
;; Maintainer : Dino Chiesa <dpchiesa@hotmail.com>
;; : Donald Curtis <dcurtis@milkbox.net>
;; Created : May 2011
;; Modified : December 2012
;; Version : 0.1.5
;; Keywords : languages mode flymake
;; X-URL : http://www.emacswiki.org/emacs/flymake-cursor.el
;; Last-saved : <2012-Dec-20 09:49:28>
;;
;; -------------------------------------------------------
;;
;; License: None. This code is in the Public Domain.
;;
;;
;; Additional functionality that makes flymake error messages appear
;; in the minibuffer when point is on a line containing a flymake
;; error. This saves having to mouse over the error, which is a
;; keyboard user's annoyance.
;; -------------------------------------------------------
;;
;; This flymake-cursor module displays the flymake error in the
;; minibuffer, after a short delay. It is based on code I found roaming
;; around on the net, unsigned and unattributed. I suppose it's public
;; domain, because, while there is a "License" listed in it, there
;; is no license holder, no one to own the license.
;;
;; This version is modified slightly from that code. The post-command fn
;; defined in this code does not display the message directly. Instead
;; it sets a timer, and when the timer fires, the timer event function
;; displays the message.
;;
;; The reason to do this: the error message is displayed only if the
;; user doesn't do anything, for about one second. This way, if the user
;; scrolls through a buffer and there are myriad errors, the minibuffer
;; is not constantly being updated.
;;
;; If the user moves away from the line with the flymake error message
;; before the timer expires, then no error is displayed in the minibuffer.
;;
;; I've also updated the names of the defuns. They all start with flyc now.
;;
;; To use this, include this line in your .emacs:
;;
;; ;; enhancements for displaying flymake errors
;; (require 'flymake-cursor)
;;
;; You can, of course, put that in an eval-after-load clause.
;;
;; -------------------------------------------------------
;;
;; Update 2012-03-06 by Donald Curtis
;; --
;; Added some autoload statements and the closing comment to make
;; compatible with package.el parser.
;;
;; Update 2012-12-20 by Jeremy Moore
;; --
;; Alter post-command-hook's local value via add-hook so that it plays
;; nicely with other packages.
;;
(require 'cl)
(defvar flyc--e-at-point nil
"Error at point, after last command")
(defvar flyc--e-display-timer nil
"A timer; when it fires, it displays the stored error message.")
(defun flyc/maybe-fixup-message (errore)
"pyflake is flakey if it has compile problems, this adjusts the
message to display, so there is one ;)"
(cond ((not (or (eq major-mode 'Python) (eq major-mode 'python-mode) t)))
((null (flymake-ler-file errore))
;; normal message do your thing
(flymake-ler-text errore))
(t ;; could not compile error
(format "compile error, problem on line %s" (flymake-ler-line errore)))))
(defun flyc/show-stored-error-now ()
"Displays the stored error in the minibuffer."
(interactive)
(let ((editing-p (= (minibuffer-depth) 0)))
(if (and flyc--e-at-point editing-p)
(progn
(message "%s" (flyc/maybe-fixup-message flyc--e-at-point))
(setq flyc--e-display-timer nil)))))
(defun flyc/-get-error-at-point ()
"Gets the first flymake error on the line at point."
(let ((line-no (line-number-at-pos))
flyc-e)
(dolist (elem flymake-err-info)
(if (eq (car elem) line-no)
(setq flyc-e (car (second elem)))))
flyc-e))
;;;###autoload
(defun flyc/show-fly-error-at-point-now ()
"If the cursor is sitting on a flymake error, display
the error message in the minibuffer."
(interactive)
(if flyc--e-display-timer
(progn
(cancel-timer flyc--e-display-timer)
(setq flyc--e-display-timer nil)))
(let ((error-at-point (flyc/-get-error-at-point)))
(if error-at-point
(progn
(setq flyc--e-at-point error-at-point)
(flyc/show-stored-error-now)))))
;;;###autoload
(defun flyc/show-fly-error-at-point-pretty-soon ()
"If the cursor is sitting on a flymake error, grab the error,
and set a timer for \"pretty soon\". When the timer fires, the error
message will be displayed in the minibuffer.
This allows a post-command-hook to NOT cause the minibuffer to be
updated 10,000 times as a user scrolls through a buffer
quickly. Only when the user pauses on a line for more than a
second, does the flymake error message (if any) get displayed.
"
(if flyc--e-display-timer
(cancel-timer flyc--e-display-timer))
(let ((error-at-point (flyc/-get-error-at-point)))
(if error-at-point
(setq flyc--e-at-point error-at-point
flyc--e-display-timer
(run-at-time "0.9 sec" nil 'flyc/show-stored-error-now))
(setq flyc--e-at-point nil
flyc--e-display-timer nil))))
;;;###autoload
(eval-after-load "flymake"
'(progn
(defadvice flymake-goto-next-error (after flyc/display-message-1 activate compile)
"Display the error in the mini-buffer rather than having to mouse over it"
(flyc/show-fly-error-at-point-now))
(defadvice flymake-goto-prev-error (after flyc/display-message-2 activate compile)
"Display the error in the mini-buffer rather than having to mouse over it"
(flyc/show-fly-error-at-point-now))
(defadvice flymake-mode (before flyc/post-command-fn activate compile)
"Add functionality to the post command hook so that if the
cursor is sitting on a flymake error the error information is
displayed in the minibuffer (rather than having to mouse over
it)"
(add-hook 'post-command-hook 'flyc/show-fly-error-at-point-pretty-soon t t))))
(provide 'flymake-cursor)
;;; flymake-cursor.el ends here
;;; flymake-easy.el --- Helpers for easily building flymake checkers
;; Copyright (C) 2012 Steve Purcell
;; Author: Steve Purcell <steve@sanityinc.com>
;; URL: https://github.com/purcell/flymake-easy
;; Version: DEV
;; Keywords: convenience, internal
;; 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides the `flymake-easy-load' helper function for
;; setting up flymake checkers. Just call that function with the
;; appropriate arguments in a major mode hook function. See
;; `flymake-ruby' for an example:
;; https://github.com/purcell/flymake-ruby
;;; Code:
(require 'flymake)
(defvar flymake-easy--active nil
"Indicates when flymake-easy-load has successfully run in this buffer.")
(defvar flymake-easy--command-fn nil
"The user-specified function for building the flymake command.")
(defvar flymake-easy--location nil
"Where to create the temp file when checking, one of 'tempdir or 'inplace.")
(defvar flymake-easy--extension nil
"The canonical file name extension to use for the current file.")
(mapc 'make-variable-buffer-local
'(flymake-easy--active
flymake-easy--command-fn
flymake-easy--location
flymake-easy--extension))
(defun flymake-easy--tempfile-in-temp-dir (file-name prefix)
"Create a temporary file for storing the contents of FILE-NAME in the system tempdir.
Argument PREFIX temp file prefix, supplied by flymake."
(make-temp-file (or prefix "flymake-easy")
nil
(concat "." flymake-easy--extension)))
(defun flymake-easy--flymake-init ()
"A catch-all flymake init function for use in `flymake-allowed-file-name-masks'."
(let* ((tempfile
(flymake-init-create-temp-buffer-copy
(cond
((eq 'tempdir flymake-easy--location)
'flymake-easy--tempfile-in-temp-dir)
((eq 'inplace flymake-easy--location)
'flymake-create-temp-inplace)
(t
(error "unknown location for flymake-easy: %s" flymake-easy--location)))))
(command (funcall flymake-easy--command-fn tempfile)))
(list (car command) (cdr command))))
(defun flymake-easy-exclude-buffer-p ()
"Whether to skip flymake in the current buffer."
(and (fboundp 'tramp-tramp-file-p)
(buffer-file-name)
(tramp-tramp-file-p (buffer-file-name))))
(defun flymake-easy-load (command-fn &optional err-line-patterns location extension warning-re info-re)
"Enable flymake in the containing buffer using a specific narrow configuration.
Argument COMMAND-FN function called to build the
command line to run (receives filename, returns list).
Argument ERR-LINE-PATTERNS patterns for identifying errors (see `flymake-err-line-patterns').
Argument EXTENSION a canonical extension for this type of source file, e.g. \"rb\".
Argument LOCATION where to create the temporary copy: one of 'tempdir (default) or 'inplace.
Argument WARNING-RE a pattern which identifies error messages as warnings.
Argument INFO-RE a pattern which identifies messages as infos (supported only
by the flymake fork at https://github.com/illusori/emacs-flymake)."
(let ((executable (car (funcall command-fn "dummy"))))
(if (executable-find executable) ;; TODO: defer this checking
(unless (flymake-easy-exclude-buffer-p)
(setq flymake-easy--command-fn command-fn
flymake-easy--location (or location 'tempdir)
flymake-easy--extension extension
flymake-easy--active t)
(set (make-local-variable 'flymake-allowed-file-name-masks)
'(("." flymake-easy--flymake-init)))
(when err-line-patterns
(set (make-local-variable 'flymake-err-line-patterns) err-line-patterns))
(dolist (var '(flymake-warning-re flymake-warn-line-regexp))
(set (make-local-variable var) (or warning-re "^[wW]arn")))
(when (boundp 'flymake-info-line-regexp)
(set (make-local-variable 'flymake-info-line-regexp)
(or info-re "^[iI]nfo")))
(flymake-mode t))
(message "Not enabling flymake: '%s' program not found" executable))))
;; Internal overrides for flymake
(defun flymake-easy--find-all-matches (str)
"Return every match for `flymake-err-line-patterns' in STR.
This is a judicious override for `flymake-split-output', enabled
by the advice below, which allows for matching multi-line
patterns."
(let (matches
(last-match-end-pos 0))
(dolist (pattern flymake-err-line-patterns)
(let ((regex (car pattern))
(pos 0))
(while (string-match regex str pos)
(push (match-string 0 str) matches)
(setq pos (match-end 0)))
(setq last-match-end-pos (max pos last-match-end-pos))))
(let ((residual (substring str last-match-end-pos)))
(list matches
(unless (string= "" residual) residual)))))
(defadvice flymake-split-output (around flymake-easy--split-output (output) activate protect)
"Override `flymake-split-output' to support mult-line error messages."
(setq ad-return-value (if flymake-easy--active
(flymake-easy--find-all-matches output)
ad-do-it)))
(defadvice flymake-post-syntax-check (before flymake-easy--force-check-was-interrupted activate)
(when flymake-easy--active
(setq flymake-check-was-interrupted t)))
(provide 'flymake-easy)
;; Local Variables:
;; coding: utf-8
;; byte-compile-warnings: (not cl-functions)
;; eval: (checkdoc-minor-mode 1)
;; End:
;;; flymake-easy.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment