From eb7fa99cc8afbc47306f112eed8f9a68d4cd06ef Mon Sep 17 00:00:00 2001 From: benj Date: Sat, 17 Mar 2018 20:03:19 -0700 Subject: 1. refactored snippets into templates 2. added slime for common lisp 3. created some auto-templates for c --- auto-insert/template.c | 7 --- init.el | 3 ++ settings/sane-defaults.el | 2 +- settings/setup-auto-insert-mode.el | 2 +- settings/setup-lisp-mode.el | 35 ++++++++++++++ settings/setup-slime-mode.el | 32 +++++++++++++ settings/setup-web-mode.el | 2 + settings/setup-yasnippet.el | 2 +- snippets/c-mode/doxycomments | 1 - snippets/c-mode/headerDEF | 8 ---- snippets/clojure-mode/defn | 8 ---- snippets/clojure-mode/let | 5 -- snippets/doxygen/doxycomments | 48 ------------------- snippets/python-mode/import_from | 5 -- snippets/python-mode/lambda | 5 -- snippets/python-mode/print | 5 -- snippets/python-mode/print format | 5 -- snippets/python-mode/script | 10 ---- templates/auto-insert/.yas-setup.el | 73 +++++++++++++++++++++++++++++ templates/auto-insert/template.c | 7 +++ templates/auto-insert/template.h | 16 +++++++ templates/snippets/c-mode/doxycomments | 1 + templates/snippets/c-mode/headerDEF | 8 ++++ templates/snippets/clojure-mode/defn | 8 ++++ templates/snippets/clojure-mode/let | 5 ++ templates/snippets/doxygen/doxycomments | 48 +++++++++++++++++++ templates/snippets/python-mode/import_from | 5 ++ templates/snippets/python-mode/lambda | 5 ++ templates/snippets/python-mode/print | 5 ++ templates/snippets/python-mode/print format | 5 ++ templates/snippets/python-mode/script | 10 ++++ 31 files changed, 271 insertions(+), 110 deletions(-) delete mode 100644 auto-insert/template.c create mode 100644 settings/setup-lisp-mode.el create mode 100644 settings/setup-slime-mode.el delete mode 120000 snippets/c-mode/doxycomments delete mode 100644 snippets/c-mode/headerDEF delete mode 100644 snippets/clojure-mode/defn delete mode 100644 snippets/clojure-mode/let delete mode 100644 snippets/doxygen/doxycomments delete mode 100644 snippets/python-mode/import_from delete mode 100644 snippets/python-mode/lambda delete mode 100644 snippets/python-mode/print delete mode 100644 snippets/python-mode/print format delete mode 100644 snippets/python-mode/script create mode 100644 templates/auto-insert/.yas-setup.el create mode 100644 templates/auto-insert/template.c create mode 100644 templates/auto-insert/template.h create mode 120000 templates/snippets/c-mode/doxycomments create mode 100644 templates/snippets/c-mode/headerDEF create mode 100644 templates/snippets/clojure-mode/defn create mode 100644 templates/snippets/clojure-mode/let create mode 100644 templates/snippets/doxygen/doxycomments create mode 100644 templates/snippets/python-mode/import_from create mode 100644 templates/snippets/python-mode/lambda create mode 100644 templates/snippets/python-mode/print create mode 100644 templates/snippets/python-mode/print format create mode 100644 templates/snippets/python-mode/script diff --git a/auto-insert/template.c b/auto-insert/template.c deleted file mode 100644 index d9afc65..0000000 --- a/auto-insert/template.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * @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 eaec7b8..8008a22 100644 --- a/init.el +++ b/init.el @@ -75,6 +75,7 @@ org-bullets sbt-mode scala-mode + slime visual-regexp web-mode yaml-mode @@ -102,12 +103,14 @@ (require 'setup-haskell-mode) (require 'setup-ido) (require 'setup-keychain-environment) +(require 'setup-lisp-mode) (require 'setup-magit) (require 'setup-markdown-mode) (require 'setup-multiple-cursors) (require 'setup-org-mode) (require 'setup-purescript-mode) (require 'setup-scala-mode) +(require 'setup-slime-mode) (require 'setup-web-mode) (require 'setup-yaml-mode) (require 'setup-yasnippet) diff --git a/settings/sane-defaults.el b/settings/sane-defaults.el index ef7e213..a793498 100644 --- a/settings/sane-defaults.el +++ b/settings/sane-defaults.el @@ -7,7 +7,7 @@ ;; Auto refresh buffers (global-auto-revert-mode 1) -;; setup eval elsip +;; setup eval elisp (define-key global-map (kbd "C-x C-e") 'eval-last-sexp) ;; define browsers diff --git a/settings/setup-auto-insert-mode.el b/settings/setup-auto-insert-mode.el index 81284db..639a4f0 100644 --- a/settings/setup-auto-insert-mode.el +++ b/settings/setup-auto-insert-mode.el @@ -5,7 +5,7 @@ (yas-expand-snippet (buffer-string) (point-min) (point-max))) (custom-set-variables - '(auto-insert-directory (locate-user-emacs-file "auto-insert"))) + '(auto-insert-directory (locate-user-emacs-file "templates/auto-insert"))) ;; Activate globally (auto-insert-mode) diff --git a/settings/setup-lisp-mode.el b/settings/setup-lisp-mode.el new file mode 100644 index 0000000..c014d17 --- /dev/null +++ b/settings/setup-lisp-mode.el @@ -0,0 +1,35 @@ +;;; setup-lisp-mode.el --- lisp mode settings -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Benj Bellon + +;; Author: Benj Bellon +;; Keywords: lisp + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Basic settings forlisp mode + +;;; Code: + +(add-hook 'lisp-mode-hook 'enable-paredit-mode) + +(slime-mode) + +;; setup eval inferior lisp in slime +;; (define-key global-map (kbd "C-c C-e") 'slime-eval-last-expression) + +(provide 'setup-lisp-mode) +;;; setup-lisp-mode.el ends here diff --git a/settings/setup-slime-mode.el b/settings/setup-slime-mode.el new file mode 100644 index 0000000..cbba516 --- /dev/null +++ b/settings/setup-slime-mode.el @@ -0,0 +1,32 @@ +;;; setup-slime-mode.el --- slime mode settings -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Benj Bellon + +;; Author: Benj Bellon +;; Keywords: lisp + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Basic settings for slime + +;;; Code: + +(require 'slime) + +(setq inferior-lisp-program "/usr/bin/sbcl") + +(provide 'setup-slime-mode) +;;; setup-slime-mode.el ends here diff --git a/settings/setup-web-mode.el b/settings/setup-web-mode.el index 92cfec2..8aedb56 100644 --- a/settings/setup-web-mode.el +++ b/settings/setup-web-mode.el @@ -4,6 +4,7 @@ (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.json\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode)) @@ -25,6 +26,7 @@ (defun indent-offset () "Hooks for web mode." (setq web-mode-markup-indent-offset 2) + (setq web-mode-code-indent-offset 2) (setq web-mode-css-indent-offset 2) (setq web-mode-style-padding 2) (setq web-mode-script-padding 2)) diff --git a/settings/setup-yasnippet.el b/settings/setup-yasnippet.el index 5441327..ddaf46e 100644 --- a/settings/setup-yasnippet.el +++ b/settings/setup-yasnippet.el @@ -1,6 +1,6 @@ (require 'yasnippet) -(setq yas-snippet-dirs '("~/.emacs.d/snippets")) +(setq yas-snippet-dirs `(,(locate-user-emacs-file "templates/snippets"))) (yas-global-mode 1) ;; Jump to end of snippet definition diff --git a/snippets/c-mode/doxycomments b/snippets/c-mode/doxycomments deleted file mode 120000 index 62fd598..0000000 --- a/snippets/c-mode/doxycomments +++ /dev/null @@ -1 +0,0 @@ -../doxygen/doxycomments \ No newline at end of file diff --git a/snippets/c-mode/headerDEF b/snippets/c-mode/headerDEF deleted file mode 100644 index a07587b..0000000 --- a/snippets/c-mode/headerDEF +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: headerDEF -# key: #if -# -- -#ifndef -#define - -#endif \ No newline at end of file diff --git a/snippets/clojure-mode/defn b/snippets/clojure-mode/defn deleted file mode 100644 index 0907e4a..0000000 --- a/snippets/clojure-mode/defn +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: defn -# key: defn -# -- -defn ${1:name} - "${2:docstring}" - [${3:arg-list}] - $0 \ No newline at end of file diff --git a/snippets/clojure-mode/let b/snippets/clojure-mode/let deleted file mode 100644 index 426caa2..0000000 --- a/snippets/clojure-mode/let +++ /dev/null @@ -1,5 +0,0 @@ -# -*- mode: snippet -*- -# name: let -# key: let -# -- -let [$0] diff --git a/snippets/doxygen/doxycomments b/snippets/doxygen/doxycomments deleted file mode 100644 index 94209bc..0000000 --- a/snippets/doxygen/doxycomments +++ /dev/null @@ -1,48 +0,0 @@ -# -*- 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"))) diff --git a/snippets/python-mode/import_from b/snippets/python-mode/import_from deleted file mode 100644 index 767f344..0000000 --- a/snippets/python-mode/import_from +++ /dev/null @@ -1,5 +0,0 @@ -# -*- mode: snippet -*- -# name: import_from -# key: from -# -- -from $1 import $0 diff --git a/snippets/python-mode/lambda b/snippets/python-mode/lambda deleted file mode 100644 index 08b268b..0000000 --- a/snippets/python-mode/lambda +++ /dev/null @@ -1,5 +0,0 @@ -# -*- mode: snippet -*- -# name: lambda -# key: lam -# -- -lambda ${1:x}: $0 \ No newline at end of file diff --git a/snippets/python-mode/print b/snippets/python-mode/print deleted file mode 100644 index 2392fbd..0000000 --- a/snippets/python-mode/print +++ /dev/null @@ -1,5 +0,0 @@ -# -*- mode: snippet -*- -# name: print -# key: print -# -- -print("$0") \ No newline at end of file diff --git a/snippets/python-mode/print format b/snippets/python-mode/print format deleted file mode 100644 index 704cb53..0000000 --- a/snippets/python-mode/print format +++ /dev/null @@ -1,5 +0,0 @@ -# -*- mode: snippet -*- -# name: print format -# key: printf -# -- -print("$1".format($0)) \ No newline at end of file diff --git a/snippets/python-mode/script b/snippets/python-mode/script deleted file mode 100644 index 3113da9..0000000 --- a/snippets/python-mode/script +++ /dev/null @@ -1,10 +0,0 @@ -# -*- mode: snippet -*- -# name: script -# key: script -# -- -#!/usr/bin/env python -def main(): - ${1:pass} - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/templates/auto-insert/.yas-setup.el b/templates/auto-insert/.yas-setup.el new file mode 100644 index 0000000..ed5d6b9 --- /dev/null +++ b/templates/auto-insert/.yas-setup.el @@ -0,0 +1,73 @@ +;;; .yas-setup.el --- Utility functions for c-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Benj Bellon + +;; Author: Benj Bellon +;; Keywords: c + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; As description + +;;; Code: +(require 'dash) + +(defun fetch-project-path (root-dir) + "Retrieve path from project's root-dir to file as list. +NOTE: The closest parent root-dir is considered the root. +ROOT-DIR: the root directory with no path delimiters." + (let* ((full-path (locate-dominating-file buffer-file-name root-dir))) + (if full-path + (let* ((proj-root-dir (nth 1 (reverse (split-string full-path "/")))) + (full-path-list (cons proj-root-dir + (-flatten (cdr (-split-on proj-root-dir (split-string buffer-file-name "/"))))))) + + ;; turn dashes into underscores + (mapcar (lambda (x) (replace-regexp-in-string "-" "_" x)) + full-path-list)) + nil) + )) + +(defun build-include-guard-header (root-dir) + "Create a full include guard header for c files. +If the path cannot be found, just use the filename. +ROOT-DIR: the root directory with no path delimiters. +FORMAT: PROJDIR_FULL_PATH_TO_FILE_H" + (if (fetch-project-path root-dir) + (let* ((path-no-file (reverse (cdr (reverse (fetch-project-path root-dir))))) + (file-no-ext (car (split-string (car (reverse (fetch-project-path root-dir))) "\\." t)))) + (concat + (mapconcat 'identity + (mapcar 'upcase + (reverse (cons file-no-ext (reverse path-no-file)))) "_") + "_H") + ) + ;; no lazy evaluation, so just do it here + (concat + (upcase + (car (-filter (lambda (x) (not (s-blank? x))) + (split-string + (car (reverse (split-string buffer-file-name "/"))) + "\\.")))) + "_H") + )) + +(defun git-include-guard-path () + "Build include guard headers for git projects." + (build-include-guard-header ".git")) + +(provide '.yas-setup) +;;; .yas-setup.el ends here diff --git a/templates/auto-insert/template.c b/templates/auto-insert/template.c new file mode 100644 index 0000000..d9afc65 --- /dev/null +++ b/templates/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/templates/auto-insert/template.h b/templates/auto-insert/template.h new file mode 100644 index 0000000..0f9cb8e --- /dev/null +++ b/templates/auto-insert/template.h @@ -0,0 +1,16 @@ +/** + * @file `(buffer-name)` + * @brief $1 + * + * $2 + * + * @author MAGIT_USER or SYSTEM_USER + * @date `(format-time-string "%Y-%m-%d")` + */ + +#ifndef `(git-include-guard-path)` +#define `(git-include-guard-path)` + +$0 + +#endif diff --git a/templates/snippets/c-mode/doxycomments b/templates/snippets/c-mode/doxycomments new file mode 120000 index 0000000..62fd598 --- /dev/null +++ b/templates/snippets/c-mode/doxycomments @@ -0,0 +1 @@ +../doxygen/doxycomments \ No newline at end of file diff --git a/templates/snippets/c-mode/headerDEF b/templates/snippets/c-mode/headerDEF new file mode 100644 index 0000000..a07587b --- /dev/null +++ b/templates/snippets/c-mode/headerDEF @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# name: headerDEF +# key: #if +# -- +#ifndef +#define + +#endif \ No newline at end of file diff --git a/templates/snippets/clojure-mode/defn b/templates/snippets/clojure-mode/defn new file mode 100644 index 0000000..0907e4a --- /dev/null +++ b/templates/snippets/clojure-mode/defn @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# name: defn +# key: defn +# -- +defn ${1:name} + "${2:docstring}" + [${3:arg-list}] + $0 \ No newline at end of file diff --git a/templates/snippets/clojure-mode/let b/templates/snippets/clojure-mode/let new file mode 100644 index 0000000..426caa2 --- /dev/null +++ b/templates/snippets/clojure-mode/let @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: let +# key: let +# -- +let [$0] diff --git a/templates/snippets/doxygen/doxycomments b/templates/snippets/doxygen/doxycomments new file mode 100644 index 0000000..94209bc --- /dev/null +++ b/templates/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"))) diff --git a/templates/snippets/python-mode/import_from b/templates/snippets/python-mode/import_from new file mode 100644 index 0000000..767f344 --- /dev/null +++ b/templates/snippets/python-mode/import_from @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: import_from +# key: from +# -- +from $1 import $0 diff --git a/templates/snippets/python-mode/lambda b/templates/snippets/python-mode/lambda new file mode 100644 index 0000000..08b268b --- /dev/null +++ b/templates/snippets/python-mode/lambda @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: lambda +# key: lam +# -- +lambda ${1:x}: $0 \ No newline at end of file diff --git a/templates/snippets/python-mode/print b/templates/snippets/python-mode/print new file mode 100644 index 0000000..2392fbd --- /dev/null +++ b/templates/snippets/python-mode/print @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: print +# key: print +# -- +print("$0") \ No newline at end of file diff --git a/templates/snippets/python-mode/print format b/templates/snippets/python-mode/print format new file mode 100644 index 0000000..704cb53 --- /dev/null +++ b/templates/snippets/python-mode/print format @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: print format +# key: printf +# -- +print("$1".format($0)) \ No newline at end of file diff --git a/templates/snippets/python-mode/script b/templates/snippets/python-mode/script new file mode 100644 index 0000000..3113da9 --- /dev/null +++ b/templates/snippets/python-mode/script @@ -0,0 +1,10 @@ +# -*- mode: snippet -*- +# name: script +# key: script +# -- +#!/usr/bin/env python +def main(): + ${1:pass} + +if __name__ == '__main__': + main() \ No newline at end of file -- cgit v1.2.3