diff --git a/.emacs b/.emacs index e784172fb420892c2e613213aee4681141f5590f..1dacaaabf648f68a0a9662d44744d3da595dd505 100644 --- a/.emacs +++ b/.emacs @@ -1010,6 +1010,52 @@ ;; whitespace next to cursor (global-set-key (kbd "S-SPC") 'insert-postfix-whitespace) +;; Le support des abbréviations +(setq abbrev-file-name "~/.emacs.d/mes_abbrevs") +(quietly-read-abbrev-file) + +;; 1. Fonction pour gérer TAB sans récursion +(defun my-expand-or-indent () + "Essaie YASnippet, puis abbrev, puis indente, sans récursion." + (interactive) + (let ((expanded nil)) + ;; Essayer YASnippet + (when (and (bound-and-true-p yas-minor-mode) + (yas-expand)) + (setq expanded t)) + ;; Si YASnippet n’a rien fait, essayer abbrev + (when (and (not expanded) + (bound-and-true-p abbrev-mode) + (expand-abbrev)) + (setq expanded t)) + ;; Si rien n’a été expansé, indenter + (unless expanded + (indent-for-tab-command)))) + +;; 2. Associer TAB à la fonction +(global-set-key (kbd "TAB") #'my-expand-or-indent) + +;; 3. Désactiver l’expansion automatique d’abbrev sur l’espace +(defun my-space-no-expand () + "Insère un espace sans expanser d’abréviation." + (interactive) + (insert " ")) + +;; Associer l’espace à cette fonction dans les modes souhaités +(dolist (hook '(text-mode-hook prog-mode-hook)) + (add-hook hook + (lambda () + (local-set-key (kbd "SPC") #'my-space-no-expand)))) + +;; 4. Activer abbrev-mode globalement +(setq-default abbrev-mode t) + +;; 5. Activer YASnippet globalement +(yas-global-mode 1) + +;; 6. Définir une abréviation de test +(define-abbrev global-abbrev-table "btw" "by the way") + ;; Macro Google (defun google () "Google the selected region if any, display a query prompt otherwise."