The shortcut keys for compiling with GCC/g ++ are configured in section 6th of "organization and use of common Emacs configurations", as shown below:
(Defun quick-compile () "A quick compile funciton for C" (interactive) (compile (Concat "GCC" (buffer-Name (current-buffer )) "-g-PG"); compile C (Global-set-Key [(F5)] 'quick-compile); shortcut: F5
The GCC/g ++-O output parameter is not specified. If you want to make the parameter consistent with the file name opened by the current buffer, you can set it as follows:
(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 ))))));; compile C (Global-set-Key [(F5)] 'quick-compile); shortcut: F5
(File-name-sans-extension (buffer-Name (current-buffer) is used to obtain the file name of the current buffer (remove the extension)
As shown in:
You must modify the shortcut settings for GDB debugging as follows:
(Defun quick-Debug () "A quick debug funciton for C ++" (interactive); (GDB (Concat "GDB -- annotate = 3" ". out ")));; debugging (GDB (Concat "GDB -- annotate = 3" (file-name-sans-extension (buffer-Name (current-buffer ))))));; debug (Global-set-Key [(F6)] 'quick-Debug); shortcut: F6
Note: "GDB -- annotate = 3" must be added with a space to separate it from the following parameters.
Open the file to be debugged and press the F6 shortcut. GDB will automatically load the file associated with the current buffer. Of course, you can also use the following command in the existing GDB debugging window, to load the file to be debugged:
(GDB) file 6.1
The display effect is as follows:
Note:
If you use the. emacs configuration file provided in "common Emacs configuration arrangement and use", you need to make some modifications and comment out the following configurations. Otherwise, GDB multi-window debugging may fail.
; Shell, after GDB exits, the buffer is automatically closed; (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 ))))