-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle-source-header.el
49 lines (48 loc) · 1.65 KB
/
toggle-source-header.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(defvar c++-header-ext-regexp "\\.\\(hpp\\|h\\|\hh\\|H\\|\par\\)$")
(defvar c++-source-ext-regexp "\\.\\(cpp\\|c\\|\cc\\|C\\|\par\\)$")
(defvar c++-default-header-ext "hpp")
(defvar c++-default-source-ext "cpp")
(defvar c++-source-extension-list '("c" "cc" "C" "cpp" "par"))
(defvar c++-header-extension-list '("h" "hh" "H" "hpp" "par"))
(defun toggle-source-header()
"Switches to the source buffer if currently in the header buffer and vice versa."
(interactive)
(let ((buf (current-buffer))
(name (file-name-nondirectory (buffer-file-name)))
file
offs)
(setq offs (string-match c++-header-ext-regexp name))
(if offs
(let ((lst c++-source-extension-list)
(ok nil)
ext)
(setq file (substring name 0 offs))
(while (and lst (not ok))
(setq ext (car lst))
(if (get-buffer (concat file "." ext))
(progn ; Lets you evaluate more than one sexp for the true case
(setq ok t)
(switch-to-buffer (concat file "." ext))))
(if (file-exists-p (concat file "." ext))
(progn ; Lets you evaluate more than one sexp for the true case
(setq ok t)
(find-file (concat file "." ext))))
(setq lst (cdr lst))))
(let ()
(setq offs (string-match c++-source-ext-regexp name))
(if offs
(let ((lst c++-header-extension-list)
(ok nil)
ext)
(setq file (substring name 0 offs))
(while (and lst (not ok))
(setq ext (car lst))
(if (get-buffer (concat file "." ext))
(progn
(setq ok t)
(switch-to-buffer (concat file "." ext))))
(if (file-exists-p (concat file "." ext))
(progn
(setq ok t)
(find-file (concat file "." ext))))
(setq lst (cdr lst)))))))))