Emacs
Now after years of not using it, my Emacs knowledge has become rusty. Looked up the web for tutorial and found a good one:
So basically I can also compile C codes from within Emacs. I can access shell from within Emacs. I just have to create a file called .emacs in my home directory as per the instruction in the above web page and fill it with following configurations:
(global-font-lock-mode t)
(global-set-key "\C-xs" 'save-buffer)
(global-set-key "\C-xv" 'quoted-insert)
(global-set-key "\C-xg" 'goto-line)
(global-set-key "\C-xf" 'search-forward)
(global-set-key "\C-xc" 'compile)
(global-set-key "\C-xt" 'text-mode);
(global-set-key "\C-xr" 'replace-string);
(global-set-key "\C-xa" 'repeat-complex-command);
(global-set-key "\C-xm" 'manual-entry);
(global-set-key "\C-xw" 'what-line);
(global-set-key "\C-x\C-u" 'shell);
(global-set-key "\C-x0" 'overwrite-mode);
(global-set-key "\C-x\C-r" 'toggle-read-only);
(global-set-key "\C-t" 'kill-word);
(global-set-key "\C-p" 'previous-line);
(global-set-key "\C-u" 'backward-word);
(global-set-key "\C-o" 'forward-word);
(global-set-key "\C-h" 'backward-delete-char-untabify);
(global-set-key "\C-x\C-m" 'not-modified);
(setq make-backup-files 'nil);
(setq default-major-mode 'text-mode)
(setq text-mode-hook 'turn-on-auto-fill)
(set-default-font "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
(setq auto-mode-alist (cons '("\\.cxx$" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.hpp$" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.tex$" . latex-mode) auto-mode-alist))
;(require 'font-lock)
;(add-hook 'c-mode-hook 'turn-on-font-lock)
;(add-hook 'c++-mode-hook 'turn-on-font-lock)
The following is custom command to compile, run, and access terminal from within Emacs when the above config has been done:
Step Four - Compile the program and prepare the executable
- Now, to compile your program just type make at the UNIX prompt.Alternatively (and this is recommended) if you have installed the appropriate .emacs file you can continue to do everything from inside emacs:
- Use Ctrl-x b to switch back to hello_world.cpp.
- Now press Ctrl-x c and hit enter to begin the compilation.
- The screen will split into two windows (press Ctrl-x o to switch between them and Ctrl-x 1 to return to single window mode).
- If there are any errors they should be listed in the compilation window. To correct them use Ctrl-x g to go to a particular line (alternatively advanced users might like to edit their .emacs file and map the emacs command next-error onto a key of their choice).
Step Five - run the executable program
- To execute your program just type ./hello_world at the UNIX prompt.Alternatively, you can continue to work from inside emacs (with the recommended .emacs files):
- If you are not in two window mode, press Ctrl-x 2.
- If you are not in the lower of the two windows, press Ctrl-x o until you are.
- Press Ctrl-x Ctrl-u to bring up a UNIX prompt inside the current emacs window.
- Now type ./hello_world at the UNIX prompt. All the output from the program will be displayed in the emacs window.