I have change the implementation of the eassist-switch-h-cpp to suit my requirement better.
In my case, the .h file and .cpp are often located in different locations. So the original
eassist-switch-h-cpp usually gave me a error message, which is frustrating.
I've changed it to use ido-find-file to give user a chance to specify the location of the counterpair.
(defun eassist-switch-h-cpp ()
"Switch header and body file according to `eassist-header-switches' var.
The current buffer's file name extention is searched in
`eassist-header-switches' variable to find out extention for file's counterpart,
for example *.hpp <--> *.cpp."
(let* ((ext (file-name-extension (buffer-file-name)))
(base-name (eassist-string-without-last (buffer-name) (length ext)))
(base-path (eassist-string-without-last (buffer-file-name) (length ext)))
(count-ext (cdr (find-if (lambda (i) (string= (car i) ext)) eassist-header-switches))))
(loop for b in (mapcar (lambda (i) (concat base-name i)) count-ext)
when (bufferp (get-buffer b)) return
(if (get-buffer-window b)
(if (get-buffer-window b t)
(loop for c in (mapcar (lambda (count-ext) (concat base-path count-ext)) count-ext)
when (file-exists-p c) return (find-file c))
(let ((dir (ido-read-file-name "Counterpair dir: ")))
(loop for c in (mapcar
(concat dir "/" base-name ext))
when (file-exists-p c) return (find-file c))))
(message "There is no corresponding pair (header or body) file.")))
(message "It is not a header or body file! See eassist-header-switches variable.")))))