emacs常用配置 gcc o 輸出檔案指定

2021-06-09 17:43:22 字數 2096 閱讀 9856

emacs常用配置整理及使用》第6條的配置了使用gcc/g++編譯的快捷鍵,如下:

(defun quick-compile ()

"a quick compile funciton for c"

(interactive)

(compile (concat "gcc " (buffer-name (current-buffer)) " -g -pg"))) ;;編譯c

(global-set-key [(f5)] 'quick-compile) ;;快捷鍵f5

其中未指定gcc/g++ -o的輸出引數,若想該引數和當前buffer開啟的檔名保持一致,可設定如下:

(defun quick-compile ()

"a quick compile funciton for c"

(interactive)

(compile (concat "gcc " (buffer-name (current-buffer)) " -g -pg -o "

(file-name-sans-extension (buffer-name (current-buffer))) ))) ;;編譯c

(global-set-key [(f5)] 'quick-compile) ;;快捷鍵f5

其中(file-name-sans-extension (buffer-name (current-buffer)))為獲取當前buffer的檔名(去掉副檔名)

如下圖所示:

相應的gdb除錯的快捷設定也要修改,如下:

(defun quick-debug ()

"a quick debug funciton for c++"

(interactive)

;;(gdb (concat "gdb --annotate=3" " a.out"))) ;;除錯

(gdb (concat "gdb --annotate=3 " (file-name-sans-extension (buffer-name (current-buffer))) ))) ;;除錯

(global-set-key [(f6)] 'quick-debug) ;;快捷鍵f6

注意:"gdb --annotate=3 "此處要多加乙個空格,以便和後面的引數隔開。

然後開啟要除錯的檔案,按f6快捷鍵,gdb會自動載入當前buffer關聯的檔案,當然也可以在已有的gdb除錯視窗中使用如下命令,來載入要除錯的檔案:

(gdb) file 6.1
顯示效果如下:

備註:如果使用《emacs常用配置整理及使用》所提供的.emacs配置檔案,需要做一些修改,注釋掉以下配置,否則會導致gdb多視窗除錯失敗。

;;shell,gdb退出後,自動關閉該buffer

;;(add-hook 'shell-mode-hook 'mode-hook-func)

;;(add-hook 'gdb-mode-hook 'mode-hook-func)

(defun mode-hook-func ()

(set-process-sentinel (get-buffer-process (current-buffer))

#'kill-buffer-on-exit))

(defun kill-buffer-on-exit (process state)

(message "%s" state)

(if (or

(string-match "exited abnormally with code.*" state)

(string-match "finished" state))

(kill-buffer (current-buffer))))

emacs 常用配置

1,顯示行號 global linum mode 1 2,當前行高亮 global hl line mode 1 3,背景色調整 custom set faces custom set faces was added by custom.if you edit it by hand,you coul...

的vim和emacs常用配置記錄

因為經常改變工作環境,所以在這裡記錄一下我的.vimrc檔案和.emacs檔案的內容。vimrc的配置檔案,主要是設定語法高亮,和tab鍵的寬度,個人喜歡設定為4個空格的分量。set tab width set tabstop 4 set softtabstop 4 set shiftwidth 4...

emacs 字型配置

overide the default changing font size bindings to make changing more subtle defun local increase font size interactive set face attribute default nil...