summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--auto-insert/template.c7
-rw-r--r--init.el25
-rw-r--r--settings/setup-auto-insert-mode.el30
-rw-r--r--settings/setup-yasnippet.el8
l---------snippets/c-mode/doxycomments1
-rw-r--r--snippets/doxygen/doxycomments48
6 files changed, 114 insertions, 5 deletions
diff --git a/auto-insert/template.c b/auto-insert/template.c
new file mode 100644
index 0000000..d9afc65
--- /dev/null
+++ b/auto-insert/template.c
@@ -0,0 +1,7 @@
+/*
+ * @file `(buffer-name)`
+ * @brief $0
+ *
+ * @author `user-full-name`
+ * @date `(format-time-string "%Y-%m-%d")`
+ */
diff --git a/init.el b/init.el
index 879325b..eaec7b8 100644
--- a/init.el
+++ b/init.el
@@ -1,3 +1,27 @@
+;;; init.el --- initialize emacs configuration
+
+;;; Author: Benj Bellon <benjaminbellon@gmail.com>
+;;; Maintainer: Benj Bellon <benjaminbellon@gmail.com>
+;;; Homepage: https://github.com/benjbellon/emacs.d
+;;; Keywords: emacs, emacs.d, config
+
+;;; Commentary:
+
+;;; This config builds an instance of Emacs personalized for its author.
+;;; A few things of interest:
+;;; 1. C-x C-c is overriden in the GUI so it redirects to the default
+;;; *ansi-term* buffer. If you wish for this override while using
+;;; Emacs in terminal mode, provide the following ENV variable:
+;;; EMACS_OVERRIDE_C_X_C_C
+;;;
+;;; 2. init.el calls keychain-refresh-environment. If for some reason,
+;;; you do not wish for the following to be available to Emacs, add
+;;; a comment or remove the call:
+;;; SSH_AUTH_SOCK
+;;; SSH_AGENT_PID
+;;; GPG_AGENT_INFO
+;;;
+;;; Code:
(package-initialize)
;; Suppress splash screen
@@ -70,6 +94,7 @@
(add-to-list 'exec-path "/usr/local/bin")
+(require 'setup-auto-insert-mode)
(require 'setup-c++-mode)
(require 'setup-clojure-mode)
(require 'setup-ember-mode)
diff --git a/settings/setup-auto-insert-mode.el b/settings/setup-auto-insert-mode.el
new file mode 100644
index 0000000..81284db
--- /dev/null
+++ b/settings/setup-auto-insert-mode.el
@@ -0,0 +1,30 @@
+(require 'autoinsert)
+
+(defun custom/expand-yasnippet ()
+ "Replace with real stuff"
+ (yas-expand-snippet (buffer-string) (point-min) (point-max)))
+
+(custom-set-variables
+ '(auto-insert-directory (locate-user-emacs-file "auto-insert")))
+
+;; Activate globally
+(auto-insert-mode)
+(setq auto-insert-query nil)
+
+;; Some global auto-insert variables
+(setq user-full-name "Benj Bellon"
+ user-email "benjaminbellon@gmail.com")
+
+;; C
+(define-auto-insert "\\.c\\'" ["template.c" custom/expand-yasnippet])
+(define-auto-insert "\\.h\\'" ["template.h" custom/expand-yasnippet])
+
+;; C++
+(define-auto-insert "\\.cc\\'" ["template.cc" custom/expand-yasnippet])
+(define-auto-insert "\\.hh\\'" ["template.cc" custom/expand-yasnippet])
+
+;; Python
+(define-auto-insert "\\.py\\'" ["template.py" custom/expand-yasnippet])
+
+
+(provide 'setup-auto-insert-mode)
diff --git a/settings/setup-yasnippet.el b/settings/setup-yasnippet.el
index 4145574..5441327 100644
--- a/settings/setup-yasnippet.el
+++ b/settings/setup-yasnippet.el
@@ -1,13 +1,11 @@
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
-(yas-global-mode 1)
-
-(define-key yas-minor-mode-map [(tab)] nil)
-(define-key yas-minor-mode-map (kbd "TAB") nil)
+(yas-global-mode 1)
;; Jump to end of snippet definition
-(define-key yas-keymap (kbd "<return>") 'yas-exit-all-snippets)
+(define-key yas-keymap (kbd "<return>") 'yas-next-field)
+(define-key yas-keymap (kbd "C-x RET TAB") 'yas-exit-all-snippets)
(add-hook 'term-mode-hook (lambda()
(setq yas-dont-activate t)))
diff --git a/snippets/c-mode/doxycomments b/snippets/c-mode/doxycomments
new file mode 120000
index 0000000..62fd598
--- /dev/null
+++ b/snippets/c-mode/doxycomments
@@ -0,0 +1 @@
+../doxygen/doxycomments \ No newline at end of file
diff --git a/snippets/doxygen/doxycomments b/snippets/doxygen/doxycomments
new file mode 100644
index 0000000..94209bc
--- /dev/null
+++ b/snippets/doxygen/doxycomments
@@ -0,0 +1,48 @@
+# -*- mode: snippet -*-
+# name: doxcomments
+# key: dox
+# type: command
+# --
+;; Command to generate doxygen comments for c functions
+
+(defun flatten (ls)
+ "Implements standard flatten function"
+ (cond
+ ((atom ls) (list ls))
+ ((null (cdr ls)) (flatten (car ls)))
+ (t (append (flatten (car ls)) (flatten (cdr ls))))))
+
+(defun find-retval ()
+ "Returns the return value of the next parsed function"
+ (interactive)
+ (let ((struct-type "struct"))
+ (search-forward "(" nil t)
+ (move-beginning-of-line nil)
+ (let ((return-type (thing-at-point 'symbol)))
+ (if (string= return-type struct-type)
+ "NOT_IMPLEMENTED"
+ return-type))))
+
+(defun find-args ()
+ "Returns a list of function args for the next parsed function"
+ (interactive)
+ (let* ((struct-type "struct")
+ (start (search-forward "(" nil t))
+ (end (search-forward ")" nil t))
+ (args-string (buffer-substring-no-properties start (1- end)))
+ (args (mapcar 'string-trim-left (split-string args-string "," t))))
+ (mapcar (lambda (x) (car (reverse x))) (mapcar 'split-string args))))
+
+(let* ((retval (find-retval))
+ (args (find-args))
+ (args-len (length args))
+ (brief "@brief $1\n *")
+ (params (mapcar (lambda (x) (format "@param: %s ${%d:}" (cdr x) (car x)))
+ (mapcar* 'cons
+ (mapcar '1+ (number-sequence 1 args-len))
+ args)))
+ (retval (format "@return %s $0" retval))
+ (snippet-text (mapconcat 'identity (flatten (list "/**" brief params (concat "\n * " retval)))
+ "\n * ")))
+ (move-beginning-of-line nil)
+ (yas-expand-snippet (concat snippet-text "\n*/\n")))