Finish configuring C/C++ dev environment

This commit is contained in:
Wojciech Kozlowski 2017-09-02 20:37:40 +01:00
parent d30f9de88c
commit 35fb803dec
6 changed files with 224 additions and 5 deletions

2
.gitignore vendored
View File

@ -6,4 +6,6 @@ recentf
places
projectile-bookmarks.eld
projectile.cache
semanticdb
ede-projects.el
*~

View File

@ -96,11 +96,12 @@
;; Load modules.
;; --------------------------------------------------------------------------
(emodule/init '(
(emodule/init-debug '(
editing
emacs
files
helm
helm-gtags
parentheses
programming
terminal
@ -130,3 +131,4 @@
(load custom-file 'noerror)
) ;; Reset garbage collection settings.
(put 'narrow-to-region 'disabled nil)

View File

@ -17,7 +17,8 @@
(setq emodule/files-packages
'(vlf)
'(recentf-ext
vlf)
)
@ -30,6 +31,7 @@
;; --------------------------------------------------------------------------
(use-package vlf-integrate
:defer t
:init
(setq-default vlf-application 'dont-ask))
@ -109,7 +111,7 @@
;; Remember location in file.
;; --------------------------------------------------------------------------
(use-package save-place
(use-package saveplace
:init
(save-place-mode 1))

65
modules/helm-gtags.el Normal file
View File

@ -0,0 +1,65 @@
;;; helm-gtags.el --- Module file for GTAGS with Helm configuration.
;;
;; Copyright (C) 2017 Wojciech Kozlowski
;;
;; Author: Wojciech Kozlowski <wojciech.kozlowski@vivaldi.net>
;; Created: 2 Sep 2017
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; This module sets up configuration for using gtags with helm.
;;
;; To add gtags for system include paths:
;;
;; export GTAGSLIBPATH=$HOME/.gtags/
;;
;; mkdir ~/.gtags
;; cd ~/.gtags
;;
;; ln -s /usr/include usr-include
;; ln -s /usr/local/include/ usr-local-include
;;
;; gtags -c
;;
;;; License: GPLv3
;;; Required packages:
(setq emodule/helm-gtags-packages
'(helm-gtags)
)
;;; Configuration:
(defun emodule/helm-gtags-init ()
(use-package helm-gtags
:defer t
:init
(add-hook 'dired-mode-hook 'helm-gtags-mode)
(add-hook 'eshell-mode-hook 'helm-gtags-mode)
(add-hook 'c-mode-hook 'helm-gtags-mode)
(add-hook 'c++-mode-hook 'helm-gtags-mode)
(add-hook 'asm-mode-hook 'helm-gtags-mode)
(setq
helm-gtags-ignore-case t
helm-gtags-auto-update t
helm-gtags-use-input-at-cursor t
helm-gtags-pulse-at-cursor t
helm-gtags-prefix-key "\C-cg"
helm-gtags-suggested-key-mapping t
)
:config
(define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
(define-key helm-gtags-mode-map (kbd "C-c g h") 'helm-gtags-show-stack)
(define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
(define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
(define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
(define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
(define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))
)

View File

@ -19,7 +19,8 @@
'(helm
helm-descbinds
helm-projectile)
helm-projectile
swiper-helm)
)
@ -121,6 +122,11 @@
(projectile-global-mode)
:config
(setq-default projectile-completion-system 'helm)
(helm-projectile-on)))
(helm-projectile-on))
(use-package swiper-helm
:defer t
:bind
(("M-s M-s" . swiper-helm))))
)

View File

@ -19,12 +19,16 @@
(setq emodule/programming-packages
'(company
company-c-headers
function-args
flycheck
flycheck-pos-tip
highlight-numbers
highlight-symbol
racer
rust-mode
sr-speedbar
stickyfunc-enhance
yasnippet)
)
@ -41,8 +45,50 @@
:init
(add-hook 'after-init-hook 'global-company-mode)
:config
;; For this to correctly complete headers, need to add all include paths to
;; `company-c-headers-path-system'.
(add-to-list 'company-backends 'company-c-headers)
(setq company-backends (delete 'company-clang company-backends)))
;; Functions args -----------------------------------------------------------
(use-package function-args
:init
(use-package ivy)
(fa-config-default)
:config
(defun set-other-window-key ()
;; function-args overrides the custom "M-o" binding, this undoes it
(define-key function-args-mode-map (kbd "M-o") nil)
(define-key function-args-mode-map (kbd "M-O") 'moo-complete))
(defun set-moo-jump-directory-key ()
;; function-args overrides the default "C-M-k" binding, this undoes it
(define-key function-args-mode-map (kbd "C-M-k") nil)
(define-key function-args-mode-map (kbd "C-M-;") 'moo-jump-directory))
(defun set-fa-idx-cycle-keys ()
;; function-args overrides the default "M-h" and "M-p" bindings, this
;; undoes it
(define-key function-args-mode-map (kbd "M-h") nil)
(define-key function-args-mode-map (kbd "M-[") 'fa-idx-cycle-up)
(define-key function-args-mode-map (kbd "M-n") nil)
(define-key function-args-mode-map (kbd "M-]") 'fa-idx-cycle-down))
(defun set-fa-abort-key ()
;; function-args overrides the default "C-M-k" binding, this undoes it
(define-key function-args-mode-map (kbd "M-u") nil)
(define-key function-args-mode-map (kbd "M-k") 'fa-abort))
(defun set-function-args-keys ()
;; Collects all the function-args key overrides
(set-other-window-key)
(set-moo-jump-directory-key)
(set-fa-idx-cycle-keys)
(set-fa-abort-key))
(add-hook 'function-args-mode-hook #'set-function-args-keys))
;; --------------------------------------------------------------------------
;; Flycheck mode.
;; --------------------------------------------------------------------------
@ -99,6 +145,67 @@
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t))
;; --------------------------------------------------------------------------
;; Speedbar.
;; --------------------------------------------------------------------------
(use-package sr-speedbar
:defer t
:bind
(("C-c s" . sr-speedbar-toggle))
:config
(setq-default
sr-speedbar-skip-other-window-p t
sr-speedbar-right-side nil
speedbar-show-unknown-files t)
(defun x-before-save-selected-window ()
(cons (selected-window)
;; We save and restore all frames' selected windows, because
;; `select-window' can change the frame-selected-window of
;; whatever frame that window is in. Each text terminal's
;; top-frame is preserved by putting it last in the list.
(apply #'append
(mapcar (lambda (terminal)
(let ((frames (frames-on-display-list terminal))
(top-frame (tty-top-frame terminal))
alist)
(if top-frame
(setq frames
(cons top-frame
(delq top-frame frames))))
(dolist (f frames)
(push (cons f (frame-selected-window f))
alist))
alist))
(terminal-list)))))
(defun x-after-save-selected-window (state)
(dolist (elt (cdr state))
(and (frame-live-p (car elt))
(window-live-p (cdr elt))
(set-frame-selected-window (car elt) (cdr elt) 'norecord)))
(when (window-live-p (car state))
(select-window (car state) 'norecord)))
(defun goto-speedbar ()
"Change window to speedbar's window.
This function assumes that the speedbar is either the left-
or right-most window"
(interactive)
(let ((selected-window (x-before-save-selected-window)))
(loop
(condition-case nil
(if sr-speedbar-right-side
(windmove-right)
(windmove-left))
(user-error (progn
(unless (string= major-mode "speedbar-mode")
(x-after-save-selected-window selected-window))
(return)))))))
(global-set-key (kbd "M-m") #'goto-speedbar))
;; --------------------------------------------------------------------------
;; Enable yasnippet.
;; --------------------------------------------------------------------------
@ -107,6 +214,41 @@
:init
(yas-global-mode 1))
;; --------------------------------------------------------------------------
;; Configure CEDET.
;; --------------------------------------------------------------------------
(use-package cc-mode
:defer t)
;; To add include paths for semantic to parse, add them to
;; `semantic-add-system-include'. This includes any local system includes,
;; such as those in `/usr/local/include'.
(use-package semantic
:init
(global-semanticdb-minor-mode 1)
(global-semantic-idle-scheduler-mode 1)
(semantic-mode 1)
:config
(use-package stickyfunc-enhance)
(add-to-list 'semantic-default-submodes 'global-semantic-stickyfunc-mode)
)
;; For this to work, need to specify project roots in the variable
;; `ede-cpp-root-project', e.g.
;; (ede-cpp-root-project "project_root"
;; :file "/dir/to/project_root/Makefile"
;; :include-path '("/include1"
;; "/include2") ;; add more include
;; ;; paths here
;; :system-include-path '("~/linux"))
;; May need to run `semantic-force-refresh' afterwards.
(use-package ede
:init
(global-ede-mode))
(add-hook 'c-mode-common-hook 'hs-minor-mode)
;; --------------------------------------------------------------------------
;; Debugging options.
;; --------------------------------------------------------------------------