Add snippets for ‘oni-python’
This commit is contained in:
parent
e530fbfc5f
commit
5ad89196c2
12 changed files with 128 additions and 3 deletions
|
@ -76,6 +76,16 @@ package-oni-php:
|
||||||
paths:
|
paths:
|
||||||
- oni-php/dist/
|
- oni-php/dist/
|
||||||
|
|
||||||
|
package-oni-python:
|
||||||
|
stage: pre-package-multifile
|
||||||
|
before_script:
|
||||||
|
- rm -rf oni-elisp/dist
|
||||||
|
script:
|
||||||
|
- cask --path oni-python package
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- oni-python/dist/
|
||||||
|
|
||||||
test-oni-alert:
|
test-oni-alert:
|
||||||
stage: test
|
stage: test
|
||||||
script: make test-oni-alert
|
script: make test-oni-alert
|
||||||
|
@ -130,6 +140,7 @@ package:
|
||||||
- package-oni-html
|
- package-oni-html
|
||||||
- package-oni-nxml
|
- package-oni-nxml
|
||||||
- package-oni-php
|
- package-oni-php
|
||||||
|
- package-oni-python
|
||||||
before_script:
|
before_script:
|
||||||
- rm -rf bin/
|
- rm -rf bin/
|
||||||
- mkdir bin/
|
- mkdir bin/
|
||||||
|
|
16
GNUmakefile
16
GNUmakefile
|
@ -4,7 +4,7 @@ PACKAGE_TARGETS := $(addprefix package-,$(FILES))
|
||||||
|
|
||||||
package: $(PACKAGE_TARGETS) package-oni-conf package-oni-css package-oni-elisp \
|
package: $(PACKAGE_TARGETS) package-oni-conf package-oni-css package-oni-elisp \
|
||||||
package-oni-haml package-oni-html package-oni-nxml package-oni-org \
|
package-oni-haml package-oni-html package-oni-nxml package-oni-org \
|
||||||
package-oni-php
|
package-oni-php package-oni-python
|
||||||
|
|
||||||
package-%: %
|
package-%: %
|
||||||
emacs --batch \
|
emacs --batch \
|
||||||
|
@ -60,6 +60,12 @@ package-oni-php:
|
||||||
--funcall package-initialize \
|
--funcall package-initialize \
|
||||||
--eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))"
|
--eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))"
|
||||||
|
|
||||||
|
package-oni-python:
|
||||||
|
emacs --batch \
|
||||||
|
--load oni-package.el \
|
||||||
|
--funcall package-initialize \
|
||||||
|
--eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-python/dist/*.tar\") #'string>)))"
|
||||||
|
|
||||||
install-%:
|
install-%:
|
||||||
emacs --batch \
|
emacs --batch \
|
||||||
--load oni-package.el \
|
--load oni-package.el \
|
||||||
|
@ -132,6 +138,14 @@ install-oni-php:
|
||||||
$(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \
|
$(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \
|
||||||
--eval "(package-install-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))"
|
--eval "(package-install-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))"
|
||||||
|
|
||||||
|
install-oni-python:
|
||||||
|
emacs --batch \
|
||||||
|
--load oni-package.el \
|
||||||
|
--fluncall package-initialize \
|
||||||
|
--eval '(package-refresh-contents)' \
|
||||||
|
$(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \
|
||||||
|
--eval "(package-install-file (car (sort (file-expand-wildcards \"oni-python/dist/*.tar\") #'string>)))"
|
||||||
|
|
||||||
test-%: install-%
|
test-%: install-%
|
||||||
emacs --batch \
|
emacs --batch \
|
||||||
--load oni-package.el \
|
--load oni-package.el \
|
||||||
|
|
18
oni-python/Cask
Normal file
18
oni-python/Cask
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
(source gnu)
|
||||||
|
(source melpa)
|
||||||
|
|
||||||
|
(package-file "./oni-python.el")
|
||||||
|
|
||||||
|
(depends-on "oni-yasnippet" :git "../" :files ("oni-yasnippet.el"))
|
||||||
|
(depends-on "oni-company" :git "../" :files ("oni-company.el"))
|
||||||
|
(depends-on "company-jedi")
|
||||||
|
(depends-on "oni-fci" :git "../" :files ("oni-fci.el"))
|
||||||
|
(depends-on "oni-flycheck" :git "../" :files ("oni-flycheck.el"))
|
||||||
|
(depends-on "rainbow-delimiters")
|
||||||
|
(depends-on "reformatter")
|
||||||
|
(depends-on "traad")
|
||||||
|
(depends-on "hydra")
|
||||||
|
|
||||||
|
(files
|
||||||
|
"*.el"
|
||||||
|
("snippets" "./snippets/*"))
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 20190710075756
|
;; Version: 20190828000139
|
||||||
;; Package-Requires: (oni-company company-jedi oni-fci oni-flycheck rainbow-delimiters reformatter traad hydra)
|
;; Package-Requires: (oni-yasnippet oni-company company-jedi oni-fci oni-flycheck rainbow-delimiters reformatter traad hydra)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; 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
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
@ -40,9 +40,20 @@
|
||||||
(require 'reformatter)
|
(require 'reformatter)
|
||||||
(require 'traad)
|
(require 'traad)
|
||||||
(require 'whitespace)
|
(require 'whitespace)
|
||||||
|
(require 'yasnippet)
|
||||||
|
|
||||||
(autoload 'hl-indent-mode "hl-indent-mode")
|
(autoload 'hl-indent-mode "hl-indent-mode")
|
||||||
|
|
||||||
|
(defconst oni-python-root
|
||||||
|
(file-name-directory
|
||||||
|
(or load-file-name
|
||||||
|
(buffer-file-name)))
|
||||||
|
"The directory where ‘oni-python’ was loaded from.")
|
||||||
|
|
||||||
|
(defconst oni-python-snippets-dir
|
||||||
|
(expand-file-name "snippets" oni-python-root)
|
||||||
|
"The directory where ‘oni-python’ stores its snippets.")
|
||||||
|
|
||||||
(defun oni-python-set-fill-column ()
|
(defun oni-python-set-fill-column ()
|
||||||
"Set the `fill-column' and `comment-fill-column' for the current buffer.
|
"Set the `fill-column' and `comment-fill-column' for the current buffer.
|
||||||
|
|
||||||
|
@ -50,6 +61,13 @@ The values are taken from the PEP8 coding standard for Python."
|
||||||
(setq-local fill-column 80)
|
(setq-local fill-column 80)
|
||||||
(setq-local comment-fill-column 72))
|
(setq-local comment-fill-column 72))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun oni-python-snippets-initialize ()
|
||||||
|
"Initialize the snippets for ‘oni-python’."
|
||||||
|
(when (boundp 'yas-snippet-dirs)
|
||||||
|
(add-to-list 'yas-snippet-dirs oni-python-snippets-dir))
|
||||||
|
(yas-load-directory oni-python-snippets-dir))
|
||||||
|
|
||||||
(defun oni-python-whitespace-mode ()
|
(defun oni-python-whitespace-mode ()
|
||||||
"Set the `whitespace-style' to show the relevat whitespace.
|
"Set the `whitespace-style' to show the relevat whitespace.
|
||||||
In Python buffers it should show any tabs being used and and used
|
In Python buffers it should show any tabs being used and and used
|
||||||
|
@ -81,6 +99,11 @@ for indentation."
|
||||||
(add-hook 'python-mode-hook 'oni-python-set-fill-column)
|
(add-hook 'python-mode-hook 'oni-python-set-fill-column)
|
||||||
(add-hook 'python-mode-hook 'oni-python-whitespace-mode)
|
(add-hook 'python-mode-hook 'oni-python-whitespace-mode)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(with-eval-after-load 'python
|
||||||
|
(with-eval-after-load 'yasnippet
|
||||||
|
(oni-python-snippets-initialize)))
|
||||||
|
|
||||||
;;;###autoload(with-eval-after-load 'python (require 'oni-python))
|
;;;###autoload(with-eval-after-load 'python (require 'oni-python))
|
||||||
|
|
||||||
(provide 'oni-python)
|
(provide 'oni-python)
|
7
oni-python/snippets/python-mode/defm_empty
Normal file
7
oni-python/snippets/python-mode/defm_empty
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# name: Empty Defmethod
|
||||||
|
# key: defm
|
||||||
|
# --
|
||||||
|
def ${1:name}(self, *args, **kwargs):
|
||||||
|
'''$2'''
|
||||||
|
return super(${3:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).$1(*args, **kwargs)
|
9
oni-python/snippets/python-mode/form
Normal file
9
oni-python/snippets/python-mode/form
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: Model Form
|
||||||
|
# key: form
|
||||||
|
# --
|
||||||
|
class ${1:Model}Form(forms.ModelForm):
|
||||||
|
'''Form for the $1 model.'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = $1
|
8
oni-python/snippets/python-mode/form_valid
Normal file
8
oni-python/snippets/python-mode/form_valid
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: Record form
|
||||||
|
# key: defm
|
||||||
|
# --
|
||||||
|
@record_activity(model=${1:`(progn (re-search-backward "^[ \t]*model = \\([a-zA-Z_].*\\)$") (match-string 1))`})
|
||||||
|
def form_valid(self, form):
|
||||||
|
'''Make sure any changes to the $1 model get logged.'''
|
||||||
|
return super(${2:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).form_valid(form)
|
8
oni-python/snippets/python-mode/form_valid_with_return
Normal file
8
oni-python/snippets/python-mode/form_valid_with_return
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: form_valid with return
|
||||||
|
# key: formvalid
|
||||||
|
# --
|
||||||
|
def form_valid(self, form):
|
||||||
|
rv = super(`(let ((name (python-info-current-defun))) (substring name 0 (cl-position ?. name)))`, self).form_valid(form)
|
||||||
|
$0
|
||||||
|
return rv
|
6
oni-python/snippets/python-mode/import_from
Normal file
6
oni-python/snippets/python-mode/import_from
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# name: from ... import ...
|
||||||
|
# contributor: Tom Willemse
|
||||||
|
# key: from
|
||||||
|
# --
|
||||||
|
from ${1:module} import ${2:class_or_module}
|
7
oni-python/snippets/python-mode/method
Normal file
7
oni-python/snippets/python-mode/method
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: method
|
||||||
|
# key: defm
|
||||||
|
# --
|
||||||
|
def $1(self$2):
|
||||||
|
'''$3'''
|
||||||
|
$0
|
9
oni-python/snippets/python-mode/permission_guard
Normal file
9
oni-python/snippets/python-mode/permission_guard
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: Permission guard
|
||||||
|
# key: defm
|
||||||
|
# --
|
||||||
|
@method_decorator(permission_required('$1',
|
||||||
|
raise_exception=True))
|
||||||
|
def dispatch(self, *args, **kwargs):
|
||||||
|
'''Make sure the user has the $1 permission.'''
|
||||||
|
return super(${3:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).dispatch(*args, **kwargs)
|
5
oni-python/snippets/python-mode/url
Normal file
5
oni-python/snippets/python-mode/url
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: url
|
||||||
|
# key: url
|
||||||
|
# --
|
||||||
|
url(r'^$1', $2, name='$3'),
|
Loading…
Reference in a new issue