Skip to content
Snippets Groups Projects
Commit 87d57e01 authored by Philippe Dosch's avatar Philippe Dosch
Browse files

Abbrev et yasnippet qui marchent ensemble

parent e1cc6984
No related branches found
No related tags found
No related merge requests found
...@@ -1010,6 +1010,52 @@ ...@@ -1010,6 +1010,52 @@
;; whitespace next to cursor ;; whitespace next to cursor
(global-set-key (kbd "S-SPC") 'insert-postfix-whitespace) (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 ;; Macro Google
(defun google () (defun google ()
"Google the selected region if any, display a query prompt otherwise." "Google the selected region if any, display a query prompt otherwise."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment