Comment by brucehoult
Comment by brucehoult a day ago
I guess some people can frown on anything.
I 99% of the time use emacs in a terminal. 90% of the time over ssh or in a non-GUI VM/docker etc.
I usually install emacs-nox to speed up the install.
Vanilla emacs is fine. Maximum I scp my .emacs file from another machine, but there's actually very little in it. Mostly it's disabling the menu bar, tool bar, and scroll bars.
Usually all I'll do is adjust things such as indenting and other code formatting things to match the codebase I'm working on -- which varies from project to project anyway, and you need to do with any editor to avoid making a mess.
I do have one little elisp function that tries to find and open the header file for the C file I'm currently in, or the c, cc, cpp, c++ file for the header file I'm in.
I'll reproduce that below, if anyone cares. Please don't laugh too much at my elisp -- I probably wrote that in the 90s.
;;;;;;;;;;;; Automatic switching between source and header files ;;;;;;;;;;;;;;;;
(defvar c++-source-extension-list '("c" "cc" "C" "cpp" "c++" "pcc" "pc"))
(defvar c++-header-extension-list '("h" "hh" "H" "hpp"))
(defvar c++-header-ext-regexp "\\.\\(hpp\\|h\\|\hh\\|H\\)$")
(defvar c++-source-ext-regexp "\\.\\(cpp\\|c\\|\cc\\|C\\|pcc\\|pc\\)$")
(defun toggle-source-header()
"Switches to the source buffer if currently in the header buffer and vice versa."
(interactive)
(let* ((buf (current-buffer))
(name (file-name-nondirectory (buffer-file-name)))
(check (lambda (regexp extns)
(let ((offs (string-match regexp name)))
(if offs
(let ((file (substring name 0 offs)))
(loop for ext in extns
for test-file = (concat file "." ext)
do (if (file-exists-p test-file)
(return (find-file test-file))))))))))
(or (funcall check c++-header-ext-regexp c++-source-extension-list)
(funcall check c++-source-ext-regexp c++-header-extension-list))))
(global-set-key [?\C-c ?`] 'toggle-source-header)