emacs,強化版的eassist

來源:互聯網
上載者:User

在.cpp和.h中切換這一功能,最初在VC6的VA中用到,發覺是個不可替代的東西。

eclipse中也有,emacs中的eassist也有提供,不過只能找同一目錄,或者已經開啟的單個buffer太弱了。

 

由於最近做symbian開發,src和inc分別放標頭檔,所以在不同目錄中找.cpp和.h就變得很重要。

不過這裡更進一步:在所有開啟的檔案中,或者目錄中,找尋同目錄的.cpp或.h開啟。。

 

把這段代碼加到eassist.el中就可以了,要注意這裡改寫了函數eassist-switch-h-cpp

 

(defun get-buffer-regexp (b)<br /> (dolist (bf (buffer-list))<br /> (if (string-match b (buffer-name bf))<br /> (return bf))))<br />(defun get-buffers-regexp (b)<br /> (let (res)<br /> (dolist (bf (buffer-list) res)<br /> (if (string-match b (buffer-name bf))<br /> (add-to-list 'res bf)))))<br />(defun switch-into-buffers-completing (buffers)<br /> (let* ((names (mapcar 'buffer-name buffers))<br /> (single (= (length names) 1))<br /> choice)<br /> (if single<br /> (switch-to-buffer (car buffers))<br /> (progn<br /> (setq choice (completing-read "Multiply Target, Which One? :" names<br /> nil t (try-completion "" names)))<br /> (switch-to-buffer (get-buffer choice))))))<br />(defun switch-into-files-completing (dirs fn)<br /> (let* ((single (= (length dirs) 1))<br /> choice)<br /> (if single<br /> (find-file (concat (car dirs) fn))<br /> (progn<br /> (setq choice (completing-read (format<br /> "Multiply Target for file %s, Which One? :"<br /> fn<br /> )<br /> dirs<br /> nil t (try-completion "" dirs)))<br /> (find-file (concat choice fn) )))))<br />(defun find-file-around-buffers-and-file (fn)<br /> (remove-if-not '(lambda (dir) (file-exists-p (concat dir fn)))<br /> (remove-duplicates<br /> (mapcar 'file-name-directory<br /> (remove-if 'null (mapcar '(lambda (b) (or<br /> (buffer-file-name b)<br /> (save-excursion (set-buffer b)<br /> dired-directory)))<br /> (buffer-list))))<br /> :test 'equal)))<br />;;;###autoload<br />(defun eassist-switch-h-cpp ()<br /> "Switch header and body file according to `eassist-header-switches' var.<br />The current buffer's file name extention is searched in<br />`eassist-header-switches' variable to find out extention for file's counterpart,<br />for example *.hpp <--> *.cpp."<br /> (interactive)<br /> (let* ((ext (file-name-extension (buffer-file-name)))<br /> (base-name (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))<br /> (base-path (file-name-sans-extension (buffer-file-name)))<br /> (count-ext (cdr (find-if (lambda (i) (string= (car i) ext)) eassist-header-switches))))<br /> (cond<br /> (count-ext<br /> (unless<br /> (or<br /> (loop for b in (mapcar (lambda (i) (concat base-name "." i)) count-ext)<br /> when (get-buffers-regexp (concat "^" (regexp-quote b)))<br /> return (switch-into-buffers-completing<br /> (get-buffers-regexp (concat "^" (regexp-quote b)))))<br /> (loop for c in (mapcar (lambda (count-ext) (concat base-path "." count-ext)) count-ext)<br /> when (file-exists-p c) return (find-file c))<br /> (loop with final-dirs = nil<br /> for c in (mapcar (lambda (count-ext) (concat base-name "." count-ext)) count-ext)<br /> when (setq final-dirs (find-file-around-buffers-and-file c))<br /> return (switch-into-files-completing final-dirs c))<br /> )<br /> (message "There is no corresponding pair (header or body) file.")))<br /> (t<br /> (message "It is not a header or body file! See eassist-header-switches variable.")))))

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.