diff --git a/emacs/c-c++-gtags.el b/emacs/c-c++-gtags.el index 72fca280..34e724c2 100644 --- a/emacs/c-c++-gtags.el +++ b/emacs/c-c++-gtags.el @@ -14,6 +14,7 @@ (define-key counsel-gtags-mode-map (kbd "M-,") 'counsel-gtags-go-backward))) (use-package realgud :ensure t :pin melpa) +(use-package rmsbolt :ensure t :pin melpa) ;;; flycheck + clang-tidy. (use-package flycheck-clang-tidy :ensure t :pin melpa) @@ -40,6 +41,10 @@ ;; TODO: (setq flycheck-disabled-checkers '(c/c++-clang c/c++-gcc c/c++-cppcheck)) ;; TODO: (flycheck-select-checker 'c/c++-clang-tidy) (flycheck-c/c++-clang-or-gcc-by-project-build-path) + (when (boundp 'project-build-path) + (setq-local rmsbolt-command + (compile-command-json/rmsbolt-command + project-build-path (buffer-file-name)))) (flycheck-mode)) (add-hook 'c-mode-local-vars-hook 'my-c-c++-mode-hook2) @@ -113,6 +118,12 @@ (format "gdb %s" cmd)) #'realgud:gdb)))) +(defun c-c++-rmsbolt-this () + (interactive) + (rmsbolt-mode) + (rmsbolt-compile)) + + ;;; (when (fboundp 'general-create-definer) (my-local-leader-def :keymaps 'c-mode-base-map @@ -131,6 +142,7 @@ "r" '(:ignore t :which-key "run") "r r" 'run-executable-by-buffer-name "r d" 'debug-executable-by-buffer-name + "r b" 'c-c++-rmsbolt-this )) ;;;EOF. diff --git a/emacs/compile-commands-json.el b/emacs/compile-commands-json.el index 9636402b..f5ea8848 100644 --- a/emacs/compile-commands-json.el +++ b/emacs/compile-commands-json.el @@ -82,6 +82,28 @@ directory listing." (ht-set! result-ht inc-dir 1)))) (ht-keys result-ht))) +(defun compile-command-json/compile-command (build-dir file-name) + (interactive) + (let* ((fn (f-join build-dir "compile_commands.json")) + (file-check? (unless (f-exists? fn) + (error "File not found: %s" fn))) + (rows (json-read-file fn)) + (matching (seq-find (lambda (row) (equal (alist-get 'file row) file-name)) + rows))) + (alist-get 'command matching))) + +(defun compile-command-json/rmsbolt-command (dir-name file-name) + (let* ((cmd-parts (remove-if (lambda (s) (or (equal "-c" s) + (equal file-name s))) + (compile-commands-json/split-shellwords + (compile-command-json/compile-command dir-name file-name)))) + (pos (seq-position cmd-parts "-o")) + (cmd-parts* (seq-partition cmd-parts pos)) + (cmd-parts** (seq-concatenate 'vector + (first cmd-parts*) + (seq-drop (second cmd-parts*) 2)))) + (s-join " " cmd-parts**))) + (provide 'compile-commands-json) ;;; compile-commands-json.el ends here