From 9c8f8de0f3e00d4f862fa5c17e3b46fcd23e5f7f Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 22 Oct 2017 18:22:41 +0900 Subject: [PATCH] Put cpp config file to ~/.emacs.d/cpp.el if possible (Bug#28685) If `cpp-config-file` starts with '.', remove the '.' when putting the file to ~/.emacs.d. Suggested by Noam Postavsky * lisp/progmodes/cpp.el (cpp-locate-user-emacs-file): New function wrapping `locate-user-emacs-file`. (cpp-edit-load, cpp-edit-save): Use it. --- lisp/progmodes/cpp.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/cpp.el b/lisp/progmodes/cpp.el index 186312f333b..f49c8e934a5 100644 --- a/lisp/progmodes/cpp.el +++ b/lisp/progmodes/cpp.el @@ -568,6 +568,14 @@ You can also use the keyboard accelerators indicated like this: [K]ey." (set-window-start nil start) (goto-char pos))) +(defun cpp-locate-user-emacs-file (file) + (locate-user-emacs-file + ;; Remove initial '.' from file. + (if (eq (aref file 0) ?.) + (substring file 1) + file) + file)) + (defun cpp-edit-load () "Load cpp configuration." (interactive) @@ -576,8 +584,8 @@ You can also use the keyboard accelerators indicated like this: [K]ey." nil) ((file-readable-p cpp-config-file) (load-file cpp-config-file)) - ((file-readable-p (concat "~/" cpp-config-file)) - (load-file (concat "~/" cpp-config-file)))) + ((file-readable-p (cpp-locate-user-emacs-file cpp-config-file)) + (load-file (cpp-locate-user-emacs-file cpp-config-file)))) (if (derived-mode-p 'cpp-edit-mode) (cpp-edit-reset))) @@ -588,7 +596,7 @@ You can also use the keyboard accelerators indicated like this: [K]ey." (with-current-buffer cpp-edit-buffer (let* ((config-file (if (file-writable-p cpp-config-file) cpp-config-file - (concat "~/" cpp-config-file))) + (cpp-locate-user-emacs-file cpp-config-file))) (buffer (find-file-noselect config-file))) (set-buffer buffer) (erase-buffer) -- 2.39.2