diff options
Diffstat (limited to '.emacs.d/snippets')
| -rw-r--r-- | .emacs.d/snippets/c-mode/.yas-parents | 1 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/.yas-setup.el | 31 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/__call__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/__repr__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/__str__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/script | 3 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/with-open | 6 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/.yas-setup.el | 31 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/__call__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/__repr__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/__str__ | 7 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/script | 1 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/with-open | 6 |
13 files changed, 94 insertions, 27 deletions
diff --git a/.emacs.d/snippets/c-mode/.yas-parents b/.emacs.d/snippets/c-mode/.yas-parents index ce9828b..b269357 100644 --- a/.emacs.d/snippets/c-mode/.yas-parents +++ b/.emacs.d/snippets/c-mode/.yas-parents | |||
| @@ -1 +1,2 @@ | |||
| 1 | cc-mode | 1 | cc-mode |
| 2 | c-lang-common | ||
diff --git a/.emacs.d/snippets/python-mode.statnett/.yas-setup.el b/.emacs.d/snippets/python-mode.statnett/.yas-setup.el index 76af532..8b29215 100644 --- a/.emacs.d/snippets/python-mode.statnett/.yas-setup.el +++ b/.emacs.d/snippets/python-mode.statnett/.yas-setup.el | |||
| @@ -1,23 +1,33 @@ | |||
| 1 | (require 'yasnippet) | 1 | (require 'yasnippet) |
| 2 | (defvar yas-text) | 2 | (defvar yas-text) |
| 3 | 3 | ||
| 4 | (defvar python-split-arg-arg-regex | ||
| 5 | "\\([[:alnum:]*]+\\)\\(:[[:blank:]]*[[:alpha:]]*\\)?\\([[:blank:]]*=[[:blank:]]*[[:alnum:]]*\\)?" | ||
| 6 | "Regular expression matching an argument of a python function. | ||
| 7 | First group should give the argument name.") | ||
| 8 | |||
| 9 | (defvar python-split-arg-separator | ||
| 10 | "[[:space:]]*,[[:space:]]*" | ||
| 11 | "Regular expression matching the separator in a list of argument.") | ||
| 12 | |||
| 4 | (defun python-split-args (arg-string) | 13 | (defun python-split-args (arg-string) |
| 5 | "Split a python argument string into ((name, default)..) tuples" | 14 | "Split a python argument string ARG-STRING into a tuple of argument names." |
| 6 | (mapcar (lambda (x) | 15 | (mapcar (lambda (x) |
| 7 | (split-string x "[[:blank:]]*=[[:blank:]]*" t)) | 16 | (when (string-match python-split-arg-arg-regex x) |
| 8 | (split-string arg-string "[[:blank:]]*,[[:blank:]]*" t))) | 17 | (match-string-no-properties 1 x))) |
| 18 | (split-string arg-string python-split-arg-separator t))) | ||
| 9 | 19 | ||
| 10 | (defun python-args-to-docstring () | 20 | (defun python-args-to-docstring () |
| 11 | "return docstring format for the python arguments in yas-text" | 21 | "Return docstring format for the python arguments in yas-text." |
| 12 | (let* ((indent (concat "\n" (make-string (current-column) 32))) | 22 | (let* ((indent (concat "\n" (make-string (current-column) 32))) |
| 13 | (args (python-split-args yas-text)) | 23 | (args (python-split-args yas-text)) |
| 14 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) | 24 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) |
| 15 | (formatted-args (mapconcat | 25 | (formatted-args (mapconcat |
| 16 | (lambda (x) | 26 | (lambda (x) |
| 17 | (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " | 27 | (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " |
| 18 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) | 28 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) |
| 19 | args | 29 | args |
| 20 | indent))) | 30 | indent))) |
| 21 | (unless (string= formatted-args "") | 31 | (unless (string= formatted-args "") |
| 22 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) | 32 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) |
| 23 | 33 | ||
| @@ -33,6 +43,3 @@ | |||
| 33 | (list "\nParameters\n----------" formatted-params | 43 | (list "\nParameters\n----------" formatted-params |
| 34 | "\nReturns\n-------" formatted-ret) | 44 | "\nReturns\n-------" formatted-ret) |
| 35 | "\n")))) | 45 | "\n")))) |
| 36 | |||
| 37 | |||
| 38 | (add-hook 'python-mode-hook #'yasnippet-snippets--fixed-indent) | ||
diff --git a/.emacs.d/snippets/python-mode.statnett/__call__ b/.emacs.d/snippets/python-mode.statnett/__call__ new file mode 100644 index 0000000..e807be5 --- /dev/null +++ b/.emacs.d/snippets/python-mode.statnett/__call__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __call__ | ||
| 3 | # key: _call | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __call__(self, ${1:*args}): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode.statnett/__repr__ b/.emacs.d/snippets/python-mode.statnett/__repr__ new file mode 100644 index 0000000..85cb80f --- /dev/null +++ b/.emacs.d/snippets/python-mode.statnett/__repr__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __repr__ | ||
| 3 | # key: _repr | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __repr__(self): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode.statnett/__str__ b/.emacs.d/snippets/python-mode.statnett/__str__ new file mode 100644 index 0000000..f623df7 --- /dev/null +++ b/.emacs.d/snippets/python-mode.statnett/__str__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __str__ | ||
| 3 | # key: _str | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __str__(self): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode.statnett/script b/.emacs.d/snippets/python-mode.statnett/script index 2e8cc35..4490e07 100644 --- a/.emacs.d/snippets/python-mode.statnett/script +++ b/.emacs.d/snippets/python-mode.statnett/script | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | # key: script | 3 | # key: script |
| 4 | # -- | 4 | # -- |
| 5 | #!/usr/bin/env python | 5 | #!/usr/bin/env python |
| 6 | # -*- coding: utf-8 -*- | ||
| 7 | 6 | ||
| 8 | 7 | ||
| 9 | def main(inargs=None): | 8 | def main(inargs=None): |
| 10 | """main entry point""" | 9 | """main entry point""" |
| 11 | $0 | 10 | $0 |
| 12 | 11 | ||
| 13 | if __name__ == '__main__': | 12 | if __name__ == "__main__": |
| 14 | main() | 13 | main() |
diff --git a/.emacs.d/snippets/python-mode.statnett/with-open b/.emacs.d/snippets/python-mode.statnett/with-open new file mode 100644 index 0000000..77c7210 --- /dev/null +++ b/.emacs.d/snippets/python-mode.statnett/with-open | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: with-open | ||
| 3 | # key: wo | ||
| 4 | # -- | ||
| 5 | with open(${1:"filename"}${2:, encoding="${3:utf-8}"}${4:, mode="${5:w}"}) as ${6:myfile}: | ||
| 6 | $0 \ No newline at end of file | ||
diff --git a/.emacs.d/snippets/python-mode/.yas-setup.el b/.emacs.d/snippets/python-mode/.yas-setup.el index 76af532..8b29215 100644 --- a/.emacs.d/snippets/python-mode/.yas-setup.el +++ b/.emacs.d/snippets/python-mode/.yas-setup.el | |||
| @@ -1,23 +1,33 @@ | |||
| 1 | (require 'yasnippet) | 1 | (require 'yasnippet) |
| 2 | (defvar yas-text) | 2 | (defvar yas-text) |
| 3 | 3 | ||
| 4 | (defvar python-split-arg-arg-regex | ||
| 5 | "\\([[:alnum:]*]+\\)\\(:[[:blank:]]*[[:alpha:]]*\\)?\\([[:blank:]]*=[[:blank:]]*[[:alnum:]]*\\)?" | ||
| 6 | "Regular expression matching an argument of a python function. | ||
| 7 | First group should give the argument name.") | ||
| 8 | |||
| 9 | (defvar python-split-arg-separator | ||
| 10 | "[[:space:]]*,[[:space:]]*" | ||
| 11 | "Regular expression matching the separator in a list of argument.") | ||
| 12 | |||
| 4 | (defun python-split-args (arg-string) | 13 | (defun python-split-args (arg-string) |
| 5 | "Split a python argument string into ((name, default)..) tuples" | 14 | "Split a python argument string ARG-STRING into a tuple of argument names." |
| 6 | (mapcar (lambda (x) | 15 | (mapcar (lambda (x) |
| 7 | (split-string x "[[:blank:]]*=[[:blank:]]*" t)) | 16 | (when (string-match python-split-arg-arg-regex x) |
| 8 | (split-string arg-string "[[:blank:]]*,[[:blank:]]*" t))) | 17 | (match-string-no-properties 1 x))) |
| 18 | (split-string arg-string python-split-arg-separator t))) | ||
| 9 | 19 | ||
| 10 | (defun python-args-to-docstring () | 20 | (defun python-args-to-docstring () |
| 11 | "return docstring format for the python arguments in yas-text" | 21 | "Return docstring format for the python arguments in yas-text." |
| 12 | (let* ((indent (concat "\n" (make-string (current-column) 32))) | 22 | (let* ((indent (concat "\n" (make-string (current-column) 32))) |
| 13 | (args (python-split-args yas-text)) | 23 | (args (python-split-args yas-text)) |
| 14 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) | 24 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) |
| 15 | (formatted-args (mapconcat | 25 | (formatted-args (mapconcat |
| 16 | (lambda (x) | 26 | (lambda (x) |
| 17 | (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " | 27 | (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " |
| 18 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) | 28 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) |
| 19 | args | 29 | args |
| 20 | indent))) | 30 | indent))) |
| 21 | (unless (string= formatted-args "") | 31 | (unless (string= formatted-args "") |
| 22 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) | 32 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) |
| 23 | 33 | ||
| @@ -33,6 +43,3 @@ | |||
| 33 | (list "\nParameters\n----------" formatted-params | 43 | (list "\nParameters\n----------" formatted-params |
| 34 | "\nReturns\n-------" formatted-ret) | 44 | "\nReturns\n-------" formatted-ret) |
| 35 | "\n")))) | 45 | "\n")))) |
| 36 | |||
| 37 | |||
| 38 | (add-hook 'python-mode-hook #'yasnippet-snippets--fixed-indent) | ||
diff --git a/.emacs.d/snippets/python-mode/__call__ b/.emacs.d/snippets/python-mode/__call__ new file mode 100644 index 0000000..e807be5 --- /dev/null +++ b/.emacs.d/snippets/python-mode/__call__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __call__ | ||
| 3 | # key: _call | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __call__(self, ${1:*args}): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode/__repr__ b/.emacs.d/snippets/python-mode/__repr__ new file mode 100644 index 0000000..85cb80f --- /dev/null +++ b/.emacs.d/snippets/python-mode/__repr__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __repr__ | ||
| 3 | # key: _repr | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __repr__(self): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode/__str__ b/.emacs.d/snippets/python-mode/__str__ new file mode 100644 index 0000000..f623df7 --- /dev/null +++ b/.emacs.d/snippets/python-mode/__str__ | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: __str__ | ||
| 3 | # key: _str | ||
| 4 | # group: Special methods | ||
| 5 | # -- | ||
| 6 | def __str__(self): | ||
| 7 | return $0 | ||
diff --git a/.emacs.d/snippets/python-mode/script b/.emacs.d/snippets/python-mode/script index 2e8cc35..9637f4c 100644 --- a/.emacs.d/snippets/python-mode/script +++ b/.emacs.d/snippets/python-mode/script | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | # key: script | 3 | # key: script |
| 4 | # -- | 4 | # -- |
| 5 | #!/usr/bin/env python | 5 | #!/usr/bin/env python |
| 6 | # -*- coding: utf-8 -*- | ||
| 7 | 6 | ||
| 8 | 7 | ||
| 9 | def main(inargs=None): | 8 | def main(inargs=None): |
diff --git a/.emacs.d/snippets/python-mode/with-open b/.emacs.d/snippets/python-mode/with-open new file mode 100644 index 0000000..77c7210 --- /dev/null +++ b/.emacs.d/snippets/python-mode/with-open | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | # -*- mode: snippet -*- | ||
| 2 | # name: with-open | ||
| 3 | # key: wo | ||
| 4 | # -- | ||
| 5 | with open(${1:"filename"}${2:, encoding="${3:utf-8}"}${4:, mode="${5:w}"}) as ${6:myfile}: | ||
| 6 | $0 \ No newline at end of file | ||
