Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ageldama committed Feb 23, 2019
1 parent 46e7478 commit a8f6c9b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions emacs/c-c++-gtags.el
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.
22 changes: 22 additions & 0 deletions emacs/compile-commands-json.el
Expand Up @@ -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

0 comments on commit a8f6c9b

Please sign in to comment.