diff options
| author | Simeon Simeonov | 2024-01-10 21:49:17 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2024-01-10 21:49:17 +0100 |
| commit | ff160687915804b109fe626a5c7fbe949f227106 (patch) | |
| tree | 9838ea050edf4288234a16206aecef7c9825c62f /.emacs.d | |
| parent | 7d08994f744685d6237ae3b4defde3eb2441fa42 (diff) | |
Update markdown-mode and yasnippet. Add some new Python snippets
Diffstat (limited to '.emacs.d')
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 178 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 253 | ||||
| -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 |
15 files changed, 401 insertions, 151 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index f1aee9d..8094e02 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -659,6 +659,44 @@ markdown-header-face-* faces." | |||
| 659 | :safe 'booleanp | 659 | :safe 'booleanp |
| 660 | :package-version '(markdown-mode . "2.5")) | 660 | :package-version '(markdown-mode . "2.5")) |
| 661 | 661 | ||
| 662 | (defcustom markdown-special-ctrl-a/e nil | ||
| 663 | "Non-nil means `C-a' and `C-e' behave specially in headlines and items. | ||
| 664 | |||
| 665 | When t, `C-a' will bring back the cursor to the beginning of the | ||
| 666 | headline text. In an item, this will be the position after bullet | ||
| 667 | and check-box, if any. When the cursor is already at that | ||
| 668 | position, another `C-a' will bring it to the beginning of the | ||
| 669 | line. | ||
| 670 | |||
| 671 | `C-e' will jump to the end of the headline, ignoring the presence | ||
| 672 | of closing tags in the headline. A second `C-e' will then jump to | ||
| 673 | the true end of the line, after closing tags. This also means | ||
| 674 | that, when this variable is non-nil, `C-e' also will never jump | ||
| 675 | beyond the end of the heading of a folded section, i.e. not after | ||
| 676 | the ellipses. | ||
| 677 | |||
| 678 | When set to the symbol `reversed', the first `C-a' or `C-e' works | ||
| 679 | normally, going to the true line boundary first. Only a directly | ||
| 680 | following, identical keypress will bring the cursor to the | ||
| 681 | special positions. | ||
| 682 | |||
| 683 | This may also be a cons cell where the behavior for `C-a' and | ||
| 684 | `C-e' is set separately." | ||
| 685 | :group 'markdown | ||
| 686 | :type '(choice | ||
| 687 | (const :tag "off" nil) | ||
| 688 | (const :tag "on: after hashes/bullet and before closing tags first" t) | ||
| 689 | (const :tag "reversed: true line boundary first" reversed) | ||
| 690 | (cons :tag "Set C-a and C-e separately" | ||
| 691 | (choice :tag "Special C-a" | ||
| 692 | (const :tag "off" nil) | ||
| 693 | (const :tag "on: after hashes/bullet first" t) | ||
| 694 | (const :tag "reversed: before hashes/bullet first" reversed)) | ||
| 695 | (choice :tag "Special C-e" | ||
| 696 | (const :tag "off" nil) | ||
| 697 | (const :tag "on: before closing tags first" t) | ||
| 698 | (const :tag "reversed: after closing tags first" reversed)))) | ||
| 699 | :package-version '(markdown-mode . "2.7")) | ||
| 662 | 700 | ||
| 663 | ;;; Markdown-Specific `rx' Macro ============================================== | 701 | ;;; Markdown-Specific `rx' Macro ============================================== |
| 664 | 702 | ||
| @@ -5531,6 +5569,9 @@ Assumes match data is available for `markdown-regex-italic'." | |||
| 5531 | (define-key map (kbd "C-x n s") 'markdown-narrow-to-subtree) | 5569 | (define-key map (kbd "C-x n s") 'markdown-narrow-to-subtree) |
| 5532 | (define-key map (kbd "M-RET") 'markdown-insert-list-item) | 5570 | (define-key map (kbd "M-RET") 'markdown-insert-list-item) |
| 5533 | (define-key map (kbd "C-c C-j") 'markdown-insert-list-item) | 5571 | (define-key map (kbd "C-c C-j") 'markdown-insert-list-item) |
| 5572 | ;; Lines | ||
| 5573 | (define-key map [remap move-beginning-of-line] 'markdown-beginning-of-line) | ||
| 5574 | (define-key map [remap move-end-of-line] 'markdown-end-of-line) | ||
| 5534 | ;; Paragraphs (Markdown context aware) | 5575 | ;; Paragraphs (Markdown context aware) |
| 5535 | (define-key map [remap backward-paragraph] 'markdown-backward-paragraph) | 5576 | (define-key map [remap backward-paragraph] 'markdown-backward-paragraph) |
| 5536 | (define-key map [remap forward-paragraph] 'markdown-forward-paragraph) | 5577 | (define-key map [remap forward-paragraph] 'markdown-forward-paragraph) |
| @@ -6474,6 +6515,130 @@ a list." | |||
| 6474 | 6515 | ||
| 6475 | ;;; Movement ================================================================== | 6516 | ;;; Movement ================================================================== |
| 6476 | 6517 | ||
| 6518 | ;; This function was originally derived from `org-beginning-of-line' from org.el. | ||
| 6519 | (defun markdown-beginning-of-line (&optional n) | ||
| 6520 | "Go to the beginning of the current visible line. | ||
| 6521 | |||
| 6522 | If this is a headline, and `markdown-special-ctrl-a/e' is not nil | ||
| 6523 | or symbol `reversed', on the first attempt move to where the | ||
| 6524 | headline text hashes, and only move to beginning of line when the | ||
| 6525 | cursor is already before the hashes of the text of the headline. | ||
| 6526 | |||
| 6527 | If `markdown-special-ctrl-a/e' is symbol `reversed' then go to | ||
| 6528 | the hashes of the text on the second attempt. | ||
| 6529 | |||
| 6530 | With argument N not nil or 1, move forward N - 1 lines first." | ||
| 6531 | (interactive "^p") | ||
| 6532 | (let ((origin (point)) | ||
| 6533 | (special (pcase markdown-special-ctrl-a/e | ||
| 6534 | (`(,C-a . ,_) C-a) (_ markdown-special-ctrl-a/e))) | ||
| 6535 | deactivate-mark) | ||
| 6536 | ;; First move to a visible line. | ||
| 6537 | (if visual-line-mode | ||
| 6538 | (beginning-of-visual-line n) | ||
| 6539 | (move-beginning-of-line n) | ||
| 6540 | ;; `move-beginning-of-line' may leave point after invisible | ||
| 6541 | ;; characters if line starts with such of these (e.g., with | ||
| 6542 | ;; a link at column 0). Really move to the beginning of the | ||
| 6543 | ;; current visible line. | ||
| 6544 | (forward-line 0)) | ||
| 6545 | (cond | ||
| 6546 | ;; No special behavior. Point is already at the beginning of | ||
| 6547 | ;; a line, logical or visual. | ||
| 6548 | ((not special)) | ||
| 6549 | ;; `beginning-of-visual-line' left point before logical beginning | ||
| 6550 | ;; of line: point is at the beginning of a visual line. Bail | ||
| 6551 | ;; out. | ||
| 6552 | ((and visual-line-mode (not (bolp)))) | ||
| 6553 | ((looking-at markdown-regex-header-atx) | ||
| 6554 | ;; At a header, special position is before the title. | ||
| 6555 | (let ((refpos (match-beginning 2)) | ||
| 6556 | (bol (point))) | ||
| 6557 | (if (eq special 'reversed) | ||
| 6558 | (when (and (= origin bol) (eq last-command this-command)) | ||
| 6559 | (goto-char refpos)) | ||
| 6560 | (when (or (> origin refpos) (<= origin bol)) | ||
| 6561 | (goto-char refpos))) | ||
| 6562 | ;; Prevent automatic cursor movement caused by the command loop. | ||
| 6563 | ;; Enable disable-point-adjustment to avoid unintended cursor repositioning. | ||
| 6564 | (when (and markdown-hide-markup | ||
| 6565 | (equal (get-char-property (point) 'display) "")) | ||
| 6566 | (setq disable-point-adjustment t)))) | ||
| 6567 | ((looking-at markdown-regex-list) | ||
| 6568 | ;; At a list item, special position is after the list marker or checkbox. | ||
| 6569 | (let ((refpos (or (match-end 4) (match-end 3)))) | ||
| 6570 | (if (eq special 'reversed) | ||
| 6571 | (when (and (= (point) origin) (eq last-command this-command)) | ||
| 6572 | (goto-char refpos)) | ||
| 6573 | (when (or (> origin refpos) (<= origin (line-beginning-position))) | ||
| 6574 | (goto-char refpos))))) | ||
| 6575 | ;; No special case, already at beginning of line. | ||
| 6576 | (t nil)))) | ||
| 6577 | |||
| 6578 | ;; This function was originally derived from `org-end-of-line' from org.el. | ||
| 6579 | (defun markdown-end-of-line (&optional n) | ||
| 6580 | "Go to the end of the line, but before ellipsis, if any. | ||
| 6581 | |||
| 6582 | If this is a headline, and `markdown-special-ctrl-a/e' is not nil | ||
| 6583 | or symbol `reversed', ignore closing tags on the first attempt, | ||
| 6584 | and only move to after the closing tags when the cursor is | ||
| 6585 | already beyond the end of the headline. | ||
| 6586 | |||
| 6587 | If `markdown-special-ctrl-a/e' is symbol `reversed' then ignore | ||
| 6588 | closing tags on the second attempt. | ||
| 6589 | |||
| 6590 | With argument N not nil or 1, move forward N - 1 lines first." | ||
| 6591 | (interactive "^p") | ||
| 6592 | (let ((origin (point)) | ||
| 6593 | (special (pcase markdown-special-ctrl-a/e | ||
| 6594 | (`(,_ . ,C-e) C-e) (_ markdown-special-ctrl-a/e))) | ||
| 6595 | deactivate-mark) | ||
| 6596 | ;; First move to a visible line. | ||
| 6597 | (if visual-line-mode | ||
| 6598 | (beginning-of-visual-line n) | ||
| 6599 | (move-beginning-of-line n)) | ||
| 6600 | (cond | ||
| 6601 | ;; At a headline, with closing tags. | ||
| 6602 | ((save-excursion | ||
| 6603 | (forward-line 0) | ||
| 6604 | (and (looking-at markdown-regex-header-atx) (match-end 3))) | ||
| 6605 | (let ((refpos (match-end 2)) | ||
| 6606 | (visual-end (and visual-line-mode | ||
| 6607 | (save-excursion | ||
| 6608 | (end-of-visual-line) | ||
| 6609 | (point))))) | ||
| 6610 | ;; If `end-of-visual-line' brings us before end of line or even closing | ||
| 6611 | ;; tags, i.e., the headline spans over multiple visual lines, move | ||
| 6612 | ;; there. | ||
| 6613 | (cond ((and visual-end | ||
| 6614 | (< visual-end refpos) | ||
| 6615 | (<= origin visual-end)) | ||
| 6616 | (goto-char visual-end)) | ||
| 6617 | ((not special) (end-of-line)) | ||
| 6618 | ((eq special 'reversed) | ||
| 6619 | (if (and (= origin (line-end-position)) | ||
| 6620 | (eq this-command last-command)) | ||
| 6621 | (goto-char refpos) | ||
| 6622 | (end-of-line))) | ||
| 6623 | (t | ||
| 6624 | (if (or (< origin refpos) (>= origin (line-end-position))) | ||
| 6625 | (goto-char refpos) | ||
| 6626 | (end-of-line)))) | ||
| 6627 | ;; Prevent automatic cursor movement caused by the command loop. | ||
| 6628 | ;; Enable disable-point-adjustment to avoid unintended cursor repositioning. | ||
| 6629 | (when (and markdown-hide-markup | ||
| 6630 | (equal (get-char-property (point) 'display) "")) | ||
| 6631 | (setq disable-point-adjustment t)))) | ||
| 6632 | (visual-line-mode | ||
| 6633 | (let ((bol (line-beginning-position))) | ||
| 6634 | (end-of-visual-line) | ||
| 6635 | ;; If `end-of-visual-line' gets us past the ellipsis at the | ||
| 6636 | ;; end of a line, backtrack and use `end-of-line' instead. | ||
| 6637 | (when (/= bol (line-beginning-position)) | ||
| 6638 | (goto-char bol) | ||
| 6639 | (end-of-line)))) | ||
| 6640 | (t (end-of-line))))) | ||
| 6641 | |||
| 6477 | (defun markdown-beginning-of-defun (&optional arg) | 6642 | (defun markdown-beginning-of-defun (&optional arg) |
| 6478 | "`beginning-of-defun-function' for Markdown. | 6643 | "`beginning-of-defun-function' for Markdown. |
| 6479 | This is used to find the beginning of the defun and should behave | 6644 | This is used to find the beginning of the defun and should behave |
| @@ -10042,7 +10207,18 @@ rows and columns and the column alignment." | |||
| 10042 | 10207 | ||
| 10043 | ;; add live preview export hook | 10208 | ;; add live preview export hook |
| 10044 | (add-hook 'after-save-hook #'markdown-live-preview-if-markdown t t) | 10209 | (add-hook 'after-save-hook #'markdown-live-preview-if-markdown t t) |
| 10045 | (add-hook 'kill-buffer-hook #'markdown-live-preview-remove-on-kill t t)) | 10210 | (add-hook 'kill-buffer-hook #'markdown-live-preview-remove-on-kill t t) |
| 10211 | |||
| 10212 | ;; Add a custom keymap for `visual-line-mode' so that activating | ||
| 10213 | ;; this minor mode does not override markdown-mode's keybindings. | ||
| 10214 | ;; FIXME: Probably `visual-line-mode' should take care of this. | ||
| 10215 | (let ((oldmap (cdr (assoc 'visual-line-mode minor-mode-map-alist))) | ||
| 10216 | (newmap (make-sparse-keymap))) | ||
| 10217 | (set-keymap-parent newmap oldmap) | ||
| 10218 | (define-key newmap [remap move-beginning-of-line] nil) | ||
| 10219 | (define-key newmap [remap move-end-of-line] nil) | ||
| 10220 | (make-local-variable 'minor-mode-overriding-map-alist) | ||
| 10221 | (push `(visual-line-mode . ,newmap) minor-mode-overriding-map-alist))) | ||
| 10046 | 10222 | ||
| 10047 | ;;;###autoload | 10223 | ;;;###autoload |
| 10048 | (add-to-list 'auto-mode-alist | 10224 | (add-to-list 'auto-mode-alist |
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index c4f8ae4..f5210d5 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*- | 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2008-2023 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2008-2024 Free Software Foundation, Inc. |
| 4 | ;; Authors: pluskid <pluskid@gmail.com>, | 4 | ;; Authors: pluskid <pluskid@gmail.com>, |
| 5 | ;; João Távora <joaotavora@gmail.com>, | 5 | ;; João Távora <joaotavora@gmail.com>, |
| 6 | ;; Noam Postavsky <npostavs@gmail.com> | 6 | ;; Noam Postavsky <npostavs@gmail.com> |
| @@ -132,8 +132,7 @@ | |||
| 132 | ;;; Code: | 132 | ;;; Code: |
| 133 | 133 | ||
| 134 | (require 'cl-lib) | 134 | (require 'cl-lib) |
| 135 | (require 'eldoc) ; Needed for 24. | 135 | (require 'eldoc) ; Needed for Emacs<25. |
| 136 | (declare-function cl-progv-after "cl-extra") ; Needed for 23.4. | ||
| 137 | (require 'easymenu) | 136 | (require 'easymenu) |
| 138 | (require 'help-mode) | 137 | (require 'help-mode) |
| 139 | 138 | ||
| @@ -342,8 +341,8 @@ If non-nil insert region contents. This can be overridden on a | |||
| 342 | per-snippet basis. A value of `cua' is considered equivalent to | 341 | per-snippet basis. A value of `cua' is considered equivalent to |
| 343 | `?0' for backwards compatibility." | 342 | `?0' for backwards compatibility." |
| 344 | :type '(choice (character :tag "Insert from register") | 343 | :type '(choice (character :tag "Insert from register") |
| 345 | (const t :tag "Insert region contents") | 344 | (const :tag "Insert region contents" t) |
| 346 | (const nil :tag "Don't insert anything") | 345 | (const :tag "Don't insert anything" nil) |
| 347 | (const cua))) ; backwards compat | 346 | (const cua))) ; backwards compat |
| 348 | 347 | ||
| 349 | (defcustom yas-good-grace t | 348 | (defcustom yas-good-grace t |
| @@ -763,7 +762,7 @@ expanded.") | |||
| 763 | :help "Display some information about YASnippet"])) | 762 | :help "Display some information about YASnippet"])) |
| 764 | 763 | ||
| 765 | (define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1") | 764 | (define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1") |
| 766 | (defvar yas--extra-modes nil | 765 | (defvar yas--extra-modes nil ;FIXME: Use `defvar-local'? |
| 767 | "An internal list of modes for which to also lookup snippets. | 766 | "An internal list of modes for which to also lookup snippets. |
| 768 | 767 | ||
| 769 | This variable probably makes more sense as buffer-local, so | 768 | This variable probably makes more sense as buffer-local, so |
| @@ -773,7 +772,7 @@ ensure your use `make-local-variable' when you set it.") | |||
| 773 | "A hash table of mode symbols to `yas--table' objects.") | 772 | "A hash table of mode symbols to `yas--table' objects.") |
| 774 | 773 | ||
| 775 | (defvar yas--parents (make-hash-table) | 774 | (defvar yas--parents (make-hash-table) |
| 776 | "A hash table of mode symbols do lists of direct parent mode symbols. | 775 | "A hash table of mode symbols to lists of direct parent mode symbols. |
| 777 | 776 | ||
| 778 | This list is populated when reading the \".yas-parents\" files | 777 | This list is populated when reading the \".yas-parents\" files |
| 779 | found when traversing snippet directories with | 778 | found when traversing snippet directories with |
| @@ -805,29 +804,59 @@ which decides on the snippet to expand.") | |||
| 805 | yas--direct-keymaps)) | 804 | yas--direct-keymaps)) |
| 806 | yas--tables)) | 805 | yas--tables)) |
| 807 | 806 | ||
| 807 | (defalias 'yas--merge-ordered-lists | ||
| 808 | (if (fboundp 'merge-ordered-lists) ;Emacs≥30. | ||
| 809 | #'merge-ordered-lists | ||
| 810 | (lambda (lists) | ||
| 811 | (setq lists (delq nil lists)) | ||
| 812 | (if (null (cdr lists)) (car lists) ;Common case. | ||
| 813 | (delete-dups (apply #'append | ||
| 814 | ;; Prevent sharing the tail. | ||
| 815 | (append lists '(()) ))))))) | ||
| 816 | |||
| 817 | (defun yas--all-parents (mode) | ||
| 818 | "Like `derived-mode-all-parents' but obeying `yas--parents'." | ||
| 819 | (or (get mode 'yas--all-parents) ;; FIXME: Use `with-memoization'? | ||
| 820 | (progn | ||
| 821 | (put mode 'yas--all-parents (list mode)) ;; Stop inf-loop with cycles. | ||
| 822 | (put mode 'yas--all-parents | ||
| 823 | (if (fboundp 'derived-mode-all-parents) | ||
| 824 | (let* ((ap (derived-mode-all-parents mode)) | ||
| 825 | (extras | ||
| 826 | (mapcar (lambda (parent) | ||
| 827 | (yas--merge-ordered-lists | ||
| 828 | (mapcar #'yas--all-parents | ||
| 829 | (gethash parent yas--parents)))) | ||
| 830 | ap))) | ||
| 831 | (yas--merge-ordered-lists | ||
| 832 | (cons (append ap '(fundamental-mode)) extras))) | ||
| 833 | (cons mode | ||
| 834 | (yas--merge-ordered-lists | ||
| 835 | (mapcar #'yas--all-parents | ||
| 836 | (remq nil | ||
| 837 | `(,(or (get mode 'derived-mode-parent) | ||
| 838 | ;; Consider `fundamental-mode' | ||
| 839 | ;; as ultimate ancestor. | ||
| 840 | 'fundamental-mode) | ||
| 841 | ,(let ((alias (symbol-function mode))) | ||
| 842 | (when (symbolp alias) alias)) | ||
| 843 | ,@(gethash mode yas--parents))))))))))) | ||
| 844 | |||
| 808 | (defun yas--modes-to-activate (&optional mode) | 845 | (defun yas--modes-to-activate (&optional mode) |
| 809 | "Compute list of mode symbols that are active for `yas-expand' and friends." | 846 | "Compute list of mode symbols that are active for `yas-expand' and friends." |
| 810 | (defvar yas--dfs) ;We rely on dynbind. We could use `letrec' instead! | 847 | (let* ((modes |
| 811 | (let* ((explored (if mode (list mode) ; Building up list in reverse. | 848 | (delete-dups |
| 812 | (cons major-mode (reverse yas--extra-modes)))) | 849 | (remq nil `(,(or mode major-mode) |
| 813 | (yas--dfs | 850 | ;; FIXME: Alternative major modes should use |
| 814 | (lambda (mode) | 851 | ;; `derived-mode-add-parents', but until that |
| 815 | (cl-loop for neighbour | 852 | ;; becomes common, use `major-mode-remap-alist' |
| 816 | in (cl-list* (or (get mode 'derived-mode-parent) | 853 | ;; as a crutch to supplement the mode hierarchy. |
| 817 | ;; Consider `fundamental-mode' | 854 | ,(and (boundp 'major-mode-remap-alist) |
| 818 | ;; as ultimate ancestor. | 855 | (car (rassq (or mode major-mode) |
| 819 | 'fundamental-mode) | 856 | major-mode-remap-alist))) |
| 820 | ;; NOTE: `fboundp' check is redundant | 857 | ,@(unless mode (reverse yas--extra-modes))))))) |
| 821 | ;; since Emacs 24.4. | 858 | (yas--merge-ordered-lists |
| 822 | (and (fboundp mode) (symbol-function mode)) | 859 | (mapcar #'yas--all-parents modes)))) |
| 823 | (gethash mode yas--parents)) | ||
| 824 | when (and neighbour | ||
| 825 | (not (memq neighbour explored)) | ||
| 826 | (symbolp neighbour)) | ||
| 827 | do (push neighbour explored) | ||
| 828 | (funcall yas--dfs neighbour))))) | ||
| 829 | (mapc yas--dfs explored) | ||
| 830 | (nreverse explored))) | ||
| 831 | 860 | ||
| 832 | (defvar yas-minor-mode-hook nil | 861 | (defvar yas-minor-mode-hook nil |
| 833 | "Hook run when `yas-minor-mode' is turned on.") | 862 | "Hook run when `yas-minor-mode' is turned on.") |
| @@ -889,13 +918,8 @@ Key bindings: | |||
| 889 | The function can be called in the hook of a minor mode to | 918 | The function can be called in the hook of a minor mode to |
| 890 | activate snippets associated with that mode." | 919 | activate snippets associated with that mode." |
| 891 | (interactive | 920 | (interactive |
| 892 | (let (modes | 921 | (let ((symbol (completing-read |
| 893 | symbol) | 922 | "Activate mode: " yas--parents nil t))) |
| 894 | (maphash (lambda (k _) | ||
| 895 | (setq modes (cons (list k) modes))) | ||
| 896 | yas--parents) | ||
| 897 | (setq symbol (completing-read | ||
| 898 | "Activate mode: " modes nil t)) | ||
| 899 | (list | 923 | (list |
| 900 | (when (not (string= "" symbol)) | 924 | (when (not (string= "" symbol)) |
| 901 | (intern symbol))))) | 925 | (intern symbol))))) |
| @@ -909,9 +933,8 @@ activate snippets associated with that mode." | |||
| 909 | (list (intern | 933 | (list (intern |
| 910 | (completing-read | 934 | (completing-read |
| 911 | "Deactivate mode: " (mapcar #'list yas--extra-modes) nil t)))) | 935 | "Deactivate mode: " (mapcar #'list yas--extra-modes) nil t)))) |
| 912 | (set (make-local-variable 'yas--extra-modes) | 936 | (setq-local yas--extra-modes |
| 913 | (remove mode | 937 | (remove mode yas--extra-modes))) |
| 914 | yas--extra-modes))) | ||
| 915 | 938 | ||
| 916 | (defun yas-temp-buffer-p (&optional buffer) | 939 | (defun yas-temp-buffer-p (&optional buffer) |
| 917 | (eq (aref (buffer-name buffer) 0) ?\s)) | 940 | (eq (aref (buffer-name buffer) 0) ?\s)) |
| @@ -923,20 +946,10 @@ activate snippets associated with that mode." | |||
| 923 | Functions are called with no argument, and should return non-nil to prevent | 946 | Functions are called with no argument, and should return non-nil to prevent |
| 924 | `yas-global-mode' from enabling yasnippet in this buffer. | 947 | `yas-global-mode' from enabling yasnippet in this buffer. |
| 925 | 948 | ||
| 926 | In Emacsen < 24, this variable is buffer-local. Because | 949 | Only the global value is used. To define |
| 927 | `yas-minor-mode-on' is called by `yas-global-mode' after | ||
| 928 | executing the buffer's major mode hook, setting this variable | ||
| 929 | there is an effective way to define exceptions to the \"global\" | ||
| 930 | activation behaviour. | ||
| 931 | |||
| 932 | In Emacsen >= 24, only the global value is used. To define | ||
| 933 | per-mode exceptions to the \"global\" activation behaviour, call | 950 | per-mode exceptions to the \"global\" activation behaviour, call |
| 934 | `yas-minor-mode' with a negative argument directily in the major | 951 | `yas-minor-mode' with a negative argument directily in the major |
| 935 | mode's hook.") | 952 | mode's hook.") ;; FIXME: Why do we say "Only the global value is used"? |
| 936 | (unless (> emacs-major-version 23) | ||
| 937 | (with-no-warnings | ||
| 938 | (make-variable-buffer-local 'yas-dont-activate))) | ||
| 939 | |||
| 940 | 953 | ||
| 941 | (defun yas-minor-mode-on () | 954 | (defun yas-minor-mode-on () |
| 942 | "Turn on YASnippet minor mode. | 955 | "Turn on YASnippet minor mode. |
| @@ -1003,23 +1016,13 @@ Honour `yas-dont-activate-functions', which see." | |||
| 1003 | 1016 | ||
| 1004 | 1017 | ||
| 1005 | ;;;###autoload(autoload 'snippet-mode "yasnippet" "A mode for editing yasnippets" t nil) | 1018 | ;;;###autoload(autoload 'snippet-mode "yasnippet" "A mode for editing yasnippets" t nil) |
| 1006 | (eval-and-compile | 1019 | (define-derived-mode snippet-mode prog-mode "Snippet" |
| 1007 | (if (fboundp 'prog-mode) | 1020 | "A mode for editing yasnippets" |
| 1008 | ;; `prog-mode' is new in 24.1. | 1021 | (setq font-lock-defaults '(yas--font-lock-keywords)) |
| 1009 | (define-derived-mode snippet-mode prog-mode "Snippet" | 1022 | (setq-local require-final-newline nil) |
| 1010 | "A mode for editing yasnippets" | 1023 | (setq-local comment-start "#") |
| 1011 | (setq font-lock-defaults '(yas--font-lock-keywords)) | 1024 | (setq-local comment-start-skip "#+[\t ]*") |
| 1012 | (set (make-local-variable 'require-final-newline) nil) | 1025 | (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t)) |
| 1013 | (set (make-local-variable 'comment-start) "#") | ||
| 1014 | (set (make-local-variable 'comment-start-skip) "#+[\t ]*") | ||
| 1015 | (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t)) | ||
| 1016 | (define-derived-mode snippet-mode fundamental-mode "Snippet" | ||
| 1017 | "A mode for editing yasnippets" | ||
| 1018 | (setq font-lock-defaults '(yas--font-lock-keywords)) | ||
| 1019 | (set (make-local-variable 'require-final-newline) nil) | ||
| 1020 | (set (make-local-variable 'comment-start) "#") | ||
| 1021 | (set (make-local-variable 'comment-start-skip) "#+[\t ]*") | ||
| 1022 | (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t)))) | ||
| 1023 | 1026 | ||
| 1024 | (defun yas-snippet-mode-buffer-p () | 1027 | (defun yas-snippet-mode-buffer-p () |
| 1025 | "Return non-nil if current buffer should be in `snippet-mode'. | 1028 | "Return non-nil if current buffer should be in `snippet-mode'. |
| @@ -1721,12 +1724,10 @@ Optional PROMPT sets the prompt to use." | |||
| 1721 | (redisplay) | 1724 | (redisplay) |
| 1722 | (or | 1725 | (or |
| 1723 | (x-popup-menu | 1726 | (x-popup-menu |
| 1724 | (if (fboundp 'posn-at-point) | 1727 | (let ((x-y (posn-x-y (posn-at-point (point))))) |
| 1725 | (let ((x-y (posn-x-y (posn-at-point (point))))) | 1728 | (list (list (+ (car x-y) 10) |
| 1726 | (list (list (+ (car x-y) 10) | 1729 | (+ (cdr x-y) 20)) |
| 1727 | (+ (cdr x-y) 20)) | 1730 | (selected-window))) |
| 1728 | (selected-window))) | ||
| 1729 | t) | ||
| 1730 | `(,prompt ("title" | 1731 | `(,prompt ("title" |
| 1731 | ,@(cl-mapcar (lambda (c d) `(,(concat " " d) . ,c)) | 1732 | ,@(cl-mapcar (lambda (c d) `(,(concat " " d) . ,c)) |
| 1732 | choices | 1733 | choices |
| @@ -2100,6 +2101,9 @@ This works by stubbing a few functions, then calling | |||
| 2100 | (or (ignore-errors (car (let ((default-directory yas--loaddir)) | 2101 | (or (ignore-errors (car (let ((default-directory yas--loaddir)) |
| 2101 | (process-lines "git" "describe" | 2102 | (process-lines "git" "describe" |
| 2102 | "--tags" "--dirty")))) | 2103 | "--tags" "--dirty")))) |
| 2104 | (eval-when-compile | ||
| 2105 | (and (fboundp 'package-get-version) | ||
| 2106 | (package-get-version))) | ||
| 2103 | (when (and (featurep 'package) | 2107 | (when (and (featurep 'package) |
| 2104 | (fboundp 'package-desc-version) | 2108 | (fboundp 'package-desc-version) |
| 2105 | (fboundp 'package-version-join)) | 2109 | (fboundp 'package-version-join)) |
| @@ -2549,7 +2553,7 @@ visited file in `snippet-mode'." | |||
| 2549 | (cond ((and file (file-readable-p file)) | 2553 | (cond ((and file (file-readable-p file)) |
| 2550 | (find-file-other-window file) | 2554 | (find-file-other-window file) |
| 2551 | (snippet-mode) | 2555 | (snippet-mode) |
| 2552 | (set (make-local-variable 'yas--editing-template) template)) | 2556 | (setq-local yas--editing-template template)) |
| 2553 | (file | 2557 | (file |
| 2554 | (message "Original file %s no longer exists!" file)) | 2558 | (message "Original file %s no longer exists!" file)) |
| 2555 | (t | 2559 | (t |
| @@ -2571,9 +2575,10 @@ visited file in `snippet-mode'." | |||
| 2571 | (pp-to-string (yas--template-content template)) | 2575 | (pp-to-string (yas--template-content template)) |
| 2572 | (yas--template-content template)))) | 2576 | (yas--template-content template)))) |
| 2573 | (snippet-mode) | 2577 | (snippet-mode) |
| 2574 | (set (make-local-variable 'yas--editing-template) template) | 2578 | (setq-local yas--editing-template template) |
| 2575 | (set (make-local-variable 'default-directory) | 2579 | (setq-local default-directory |
| 2576 | (car (cdr (car (yas--guess-snippet-directories (yas--template-table template)))))))))) | 2580 | (car (cdr (car (yas--guess-snippet-directories |
| 2581 | (yas--template-table template)))))))))) | ||
| 2577 | 2582 | ||
| 2578 | (defun yas--guess-snippet-directories-1 (table) | 2583 | (defun yas--guess-snippet-directories-1 (table) |
| 2579 | "Guess possible snippet subdirectories for TABLE." | 2584 | "Guess possible snippet subdirectories for TABLE." |
| @@ -2649,11 +2654,11 @@ NO-TEMPLATE is non-nil." | |||
| 2649 | (kill-all-local-variables) | 2654 | (kill-all-local-variables) |
| 2650 | (snippet-mode) | 2655 | (snippet-mode) |
| 2651 | (yas-minor-mode 1) | 2656 | (yas-minor-mode 1) |
| 2652 | (set (make-local-variable 'yas--guessed-modes) | 2657 | (setq-local yas--guessed-modes |
| 2653 | (mapcar (lambda (d) (yas--table-mode (car d))) | 2658 | (mapcar (lambda (d) (yas--table-mode (car d))) |
| 2654 | guessed-directories)) | 2659 | guessed-directories)) |
| 2655 | (set (make-local-variable 'default-directory) | 2660 | (setq-local default-directory |
| 2656 | (car (cdr (car guessed-directories)))) | 2661 | (car (cdr (car guessed-directories)))) |
| 2657 | (if (and (not no-template) yas-new-snippet-default) | 2662 | (if (and (not no-template) yas-new-snippet-default) |
| 2658 | (yas-expand-snippet yas-new-snippet-default)))) | 2663 | (yas-expand-snippet yas-new-snippet-default)))) |
| 2659 | 2664 | ||
| @@ -2703,8 +2708,8 @@ neither do the elements of PARENTS." | |||
| 2703 | ido-mode) | 2708 | ido-mode) |
| 2704 | 'ido-completing-read 'completing-read))) | 2709 | 'ido-completing-read 'completing-read))) |
| 2705 | (unless yas--guessed-modes | 2710 | (unless yas--guessed-modes |
| 2706 | (set (make-local-variable 'yas--guessed-modes) | 2711 | (setq-local yas--guessed-modes |
| 2707 | (or (yas--compute-major-mode-and-parents buffer-file-name)))) | 2712 | (yas--compute-major-mode-and-parents buffer-file-name))) |
| 2708 | (intern | 2713 | (intern |
| 2709 | (funcall prompt (format "Choose or enter a table (yas guesses %s): " | 2714 | (funcall prompt (format "Choose or enter a table (yas guesses %s): " |
| 2710 | (if yas--guessed-modes | 2715 | (if yas--guessed-modes |
| @@ -2736,11 +2741,12 @@ Return the `yas--template' object created" | |||
| 2736 | ;; | 2741 | ;; |
| 2737 | (t | 2742 | (t |
| 2738 | (unless yas--guessed-modes | 2743 | (unless yas--guessed-modes |
| 2739 | (set (make-local-variable 'yas--guessed-modes) (or (yas--compute-major-mode-and-parents buffer-file-name)))) | 2744 | (setq-local yas--guessed-modes |
| 2745 | (or (yas--compute-major-mode-and-parents buffer-file-name)))) | ||
| 2740 | (let* ((table (yas--table-get-create table))) | 2746 | (let* ((table (yas--table-get-create table))) |
| 2741 | (set (make-local-variable 'yas--editing-template) | 2747 | (setq-local yas--editing-template |
| 2742 | (yas--define-snippets-1 (yas--parse-template buffer-file-name) | 2748 | (yas--define-snippets-1 (yas--parse-template buffer-file-name) |
| 2743 | table))))) | 2749 | table))))) |
| 2744 | (when interactive | 2750 | (when interactive |
| 2745 | (yas--message 3 "Snippet \"%s\" loaded for %s." | 2751 | (yas--message 3 "Snippet \"%s\" loaded for %s." |
| 2746 | (yas--template-name yas--editing-template) | 2752 | (yas--template-name yas--editing-template) |
| @@ -3097,14 +3103,13 @@ other fields." | |||
| 3097 | 3103 | ||
| 3098 | ;;; Snippet expansion and field management | 3104 | ;;; Snippet expansion and field management |
| 3099 | 3105 | ||
| 3100 | (defvar yas--active-field-overlay nil | 3106 | (defvar-local yas--active-field-overlay nil |
| 3101 | "Overlays the currently active field.") | 3107 | "Overlays the currently active field.") |
| 3102 | 3108 | ||
| 3103 | (defvar yas--active-snippets nil | 3109 | (defvar-local yas--active-snippets nil |
| 3104 | "List of currently active snippets") | 3110 | "List of currently active snippets") |
| 3105 | (make-variable-buffer-local 'yas--active-snippets) | ||
| 3106 | 3111 | ||
| 3107 | (defvar yas--field-protection-overlays nil | 3112 | (defvar-local yas--field-protection-overlays nil |
| 3108 | "Two overlays protect the current active field.") | 3113 | "Two overlays protect the current active field.") |
| 3109 | 3114 | ||
| 3110 | (defvar yas-selected-text nil | 3115 | (defvar yas-selected-text nil |
| @@ -3113,8 +3118,6 @@ other fields." | |||
| 3113 | (defvar yas--start-column nil | 3118 | (defvar yas--start-column nil |
| 3114 | "The column where the snippet expansion started.") | 3119 | "The column where the snippet expansion started.") |
| 3115 | 3120 | ||
| 3116 | (make-variable-buffer-local 'yas--active-field-overlay) | ||
| 3117 | (make-variable-buffer-local 'yas--field-protection-overlays) | ||
| 3118 | (put 'yas--active-field-overlay 'permanent-local t) | 3121 | (put 'yas--active-field-overlay 'permanent-local t) |
| 3119 | (put 'yas--field-protection-overlays 'permanent-local t) | 3122 | (put 'yas--field-protection-overlays 'permanent-local t) |
| 3120 | 3123 | ||
| @@ -3494,8 +3497,7 @@ This renders the snippet as ordinary text." | |||
| 3494 | 3497 | ||
| 3495 | (yas--message 4 "Snippet %s exited." (yas--snippet-id snippet))) | 3498 | (yas--message 4 "Snippet %s exited." (yas--snippet-id snippet))) |
| 3496 | 3499 | ||
| 3497 | (defvar yas--snippets-to-move nil) | 3500 | (defvar-local yas--snippets-to-move nil) |
| 3498 | (make-variable-buffer-local 'yas--snippets-to-move) | ||
| 3499 | 3501 | ||
| 3500 | (defun yas--prepare-snippets-for-move (beg end buf pos) | 3502 | (defun yas--prepare-snippets-for-move (beg end buf pos) |
| 3501 | "Gather snippets in BEG..END for moving to POS in BUF." | 3503 | "Gather snippets in BEG..END for moving to POS in BUF." |
| @@ -3762,13 +3764,10 @@ BEG, END and LENGTH like overlay modification hooks." | |||
| 3762 | 3764 | ||
| 3763 | (defun yas--merge-and-drop-dups (list1 list2 cmp key) | 3765 | (defun yas--merge-and-drop-dups (list1 list2 cmp key) |
| 3764 | ;; `delete-consecutive-dups' + `cl-merge'. | 3766 | ;; `delete-consecutive-dups' + `cl-merge'. |
| 3765 | (funcall (if (fboundp 'delete-consecutive-dups) | 3767 | (delete-consecutive-dups |
| 3766 | #'delete-consecutive-dups ; 24.4 | 3768 | (cl-merge 'list list1 list2 cmp :key key))) |
| 3767 | #'delete-dups) | ||
| 3768 | (cl-merge 'list list1 list2 cmp :key key))) | ||
| 3769 | 3769 | ||
| 3770 | (defvar yas--before-change-modified-snippets nil) | 3770 | (defvar-local yas--before-change-modified-snippets nil) |
| 3771 | (make-variable-buffer-local 'yas--before-change-modified-snippets) | ||
| 3772 | 3771 | ||
| 3773 | (defun yas--gather-active-snippets (overlay beg end then-delete) | 3772 | (defun yas--gather-active-snippets (overlay beg end then-delete) |
| 3774 | ;; Add active snippets in BEG..END into an OVERLAY keyed entry of | 3773 | ;; Add active snippets in BEG..END into an OVERLAY keyed entry of |
| @@ -3793,8 +3792,7 @@ BEG, END and LENGTH like overlay modification hooks." | |||
| 3793 | (when then-delete | 3792 | (when then-delete |
| 3794 | (cl-callf2 delq old yas--before-change-modified-snippets))))) | 3793 | (cl-callf2 delq old yas--before-change-modified-snippets))))) |
| 3795 | 3794 | ||
| 3796 | (defvar yas--todo-snippet-indent nil nil) | 3795 | (defvar-local yas--todo-snippet-indent nil nil) |
| 3797 | (make-variable-buffer-local 'yas--todo-snippet-indent) | ||
| 3798 | 3796 | ||
| 3799 | (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) | 3797 | (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) |
| 3800 | "Clears the field and updates mirrors, conditionally. | 3798 | "Clears the field and updates mirrors, conditionally. |
| @@ -4104,25 +4102,34 @@ Returns the newly created snippet." | |||
| 4104 | ;; content. | 4102 | ;; content. |
| 4105 | (let ((buffer-undo-list t)) | 4103 | (let ((buffer-undo-list t)) |
| 4106 | (goto-char begin) | 4104 | (goto-char begin) |
| 4107 | ;; Call before and after change functions manually, | 4105 | (if (> emacs-major-version 29) |
| 4108 | ;; otherwise cc-mode's cache can get messed up. Don't use | 4106 | ;; Don't use the workaround for CC-mode's cache, |
| 4109 | ;; `inhibit-modification-hooks' for that, that blocks | 4107 | ;; since it was presumably a bug in CC-mode, so either |
| 4110 | ;; overlay and text property hooks as well! FIXME: Maybe | 4108 | ;; it's fixed already, or it should get fixed. |
| 4111 | ;; use `combine-change-calls'? (Requires Emacs 27+ though.) | 4109 | (progn |
| 4112 | (run-hook-with-args 'before-change-functions begin end) | 4110 | (insert content) |
| 4113 | (let ((before-change-functions nil) | 4111 | (narrow-to-region begin (point)) |
| 4114 | (after-change-functions nil)) | 4112 | (goto-char (point-min)) |
| 4115 | ;; Some versions of cc-mode (might be the one with Emacs | 4113 | (yas--snippet-parse-create snippet)) |
| 4116 | ;; 24.3 only) fail when inserting snippet content in a | 4114 | ;; Call before and after change functions manually, |
| 4117 | ;; narrowed buffer, so make sure to insert before | 4115 | ;; otherwise cc-mode's cache can get messed up. Don't use |
| 4118 | ;; narrowing. | 4116 | ;; `inhibit-modification-hooks' for that, that blocks |
| 4119 | (insert content) | 4117 | ;; overlay and text property hooks as well! FIXME: Maybe |
| 4120 | (narrow-to-region begin (point)) | 4118 | ;; use `combine-change-calls'? (Requires Emacs 27+ though.) |
| 4121 | (goto-char (point-min)) | 4119 | (run-hook-with-args 'before-change-functions begin end) |
| 4122 | (yas--snippet-parse-create snippet)) | 4120 | (let ((before-change-functions nil) |
| 4123 | (run-hook-with-args 'after-change-functions | 4121 | (after-change-functions nil)) |
| 4124 | (point-min) (point-max) | 4122 | ;; Some versions of cc-mode (might be the one with Emacs |
| 4125 | (- end begin))) | 4123 | ;; 24.3 only) fail when inserting snippet content in a |
| 4124 | ;; narrowed buffer, so make sure to insert before | ||
| 4125 | ;; narrowing. | ||
| 4126 | (insert content) | ||
| 4127 | (narrow-to-region begin (point)) | ||
| 4128 | (goto-char (point-min)) | ||
| 4129 | (yas--snippet-parse-create snippet)) | ||
| 4130 | (run-hook-with-args 'after-change-functions | ||
| 4131 | (point-min) (point-max) | ||
| 4132 | (- end begin)))) | ||
| 4126 | (when (listp buffer-undo-list) | 4133 | (when (listp buffer-undo-list) |
| 4127 | (push (cons (point-min) (point-max)) | 4134 | (push (cons (point-min) (point-max)) |
| 4128 | buffer-undo-list)) | 4135 | buffer-undo-list)) |
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 | ||
