I'm using this yasnippet:
# -*- mode: snippet -*-
# name: ifndef
# key: ifndef
# --
#ifndef ${1:`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_HH_}
#define $1
$0
#endif
You can quickly customize it to do what you want.
In case you're not using yasnippet yet
Here's my personal config (you can take the parts that you like):
(use-package yasnippet
:diminish yas-minor-mode
:init
(progn
(setq yas-fallback-behavior 'return-nil)
(setq yas-triggers-in-field t)
(setq yas-verbosity 0)
;; I'm using my own snippets, turn bundled snippets off
;; (setq yas-snippet-dirs (list (concat emacs.d "snippets/")))
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(yas-global-mode)))
;; (package-install 'auto-yasnippet)
(global-set-key "\C-o" 'aya-open-line)
It needs auto-yasnippet
(it's in MELPA, yasnippet
is a dependency).
So now C-o will try in order to:
- expand abbrev
- expand yasnippet or move to the next yasnippet field if already expanding
- open line