From 4344bbeeda68999d5b9ac309f9137df413801204 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Sat, 23 Apr 2011 00:29:34 +0200 Subject: [PATCH] EMACS: Toggle header and source Wrote a function to toggle views between a header and source file in c-mode and locally bound this to F11. --- emacs.d/00-functions.el | 8 ++++++++ emacs.d/20-c-mode.el | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 emacs.d/20-c-mode.el diff --git a/emacs.d/00-functions.el b/emacs.d/00-functions.el index 2b43d65..ff493f0 100644 --- a/emacs.d/00-functions.el +++ b/emacs.d/00-functions.el @@ -26,3 +26,11 @@ '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))) + +(defun c-toggle-header-source () + (interactive) + (let ((ext (file-name-extension (buffer-file-name))) + (noext (file-name-sans-extension (buffer-file-name)))) + (if (string= (substring ext 0 1) "c") + (find-file (concat noext ".h")) + (find-file (concat noext ".c"))))) diff --git a/emacs.d/20-c-mode.el b/emacs.d/20-c-mode.el new file mode 100644 index 0000000..2b05b94 --- /dev/null +++ b/emacs.d/20-c-mode.el @@ -0,0 +1,3 @@ +(add-hook 'c-mode-hook + (lambda () + (local-set-key [f11] 'c-toggle-header-source)))