刚开始学习elisp,试着写些脚本

(defun switch-extension(extension)
  (if (or (string-equal extension "h") (string-equal extension "hpp"))
      "cpp"
    "h"))
(defun switch-file-name-extension(name)
  (concat (file-name-sans-extension name) "." (switch-extension (file-name-extension name))))
(defun switch-directory (directory)
  (cond ((string-match ".+/src/$" directory)
         (replace-regexp-in-string "/src/$" "/inc/" directory))
        ((string-match ".+/inc/$" directory)
         (replace-regexp-in-string "/inc/$" "/src/" directory))
        (t directory)))
(defun switch-file-path(file-path)
  (let ((extension (file-name-extension file-path)) (switched-file-path))
    (setf switched-file-path (concat (file-name-sans-extension file-path) "." (switch-extension extension)))
    (when (not (file-exists-p switched-file-path))
      (setf switched-file-path (concat (switch-directory (file-name-directory switched-file-path)) (file-name-nondirectory switched-file-path))))
    switched-file-path))
(defun switch-head-body(file-path)
  "切换头文件和实现文件"
  (find-file (switch-file-path file-path)))
(defun switch-current-file()
  "当前文件在头/实现文件之间切换"
  (interactive)
  (switch-head-body (buffer-file-name)))