例如,我有文件模型/ user.py開放,我想有打開控制器/ user.py的快捷方式。或者,我想切換到測試/模型/ testUser.py(人爲的例子)如何製作emacs快捷方式在相關文件之間切換?
我想打一個Emacs快捷方式,其給出當前打開的文件,打開以各種方式相關的文件。
例如,我有文件模型/ user.py開放,我想有打開控制器/ user.py的快捷方式。或者,我想切換到測試/模型/ testUser.py(人爲的例子)如何製作emacs快捷方式在相關文件之間切換?
我想打一個Emacs快捷方式,其給出當前打開的文件,打開以各種方式相關的文件。
如果「相關文件」遵循某種模式,我認爲這是微不足道的寫一些elisp的功能,做任務。比方說,你有一個模型,需要打開他相關的控制器,你需要做這樣的事情:
(defun my-open-related-controller()
(interactive)
(let* ((name (buffer-file-name))) ;gets the filename of the current buffer
;; Of course, this is only an example. The point here is that you need
;; to "discover" the name of the related file based on the current one.
(setf name (replace-regexp-in-string "model" "controller" name))
;; Now you will open the file(if it isn't open already) and switch to it
(find-file name)))
然後,你可以綁定功能,比方說,F5:
(define-key name-of-the-mode-map [f5] 'my-open-related-controller)
如果你想這個箱子全球約束力,用途:
(global-set-key [f5] 'my-open-related-controller)
當然,這只是一個粗的例子(因爲你沒有給許多具體細節),但應該足以讓你開始。希望能幫助到你!
因此,如果elisp沒有關閉,是否有可能更一般地寫這個?例如做一個可以調用的函數'(global-set-key [f5](make-file-switcher「controller」「model」))' –
當然:'(defun make-file-switcher(from to) '(lambda()(interactive)(find-file(replace-regexp-in-string,(regexp-quote from),to(buffer-file-name)tt)))))' – Sean
「打開以各種方式相關的文件」,你可能希望得到更多的具體的關於「各種方式」的含義。 –