diff options
| author | Simeon Simeonov | 2015-08-28 11:10:13 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2015-08-28 11:10:13 +0200 |
| commit | 3ec6ac6a8d888043cc12dfe6f77adcd0cfc1b086 (patch) | |
| tree | c2382110856abc0cae77f8360ea2b0d8962d07f9 /.emacs.d | |
| parent | eeeaae3a34ca050c9ea30aa3950dc91db70b9b1a (diff) | |
Upgrade all, add yaml, few snippet fixes
Diffstat (limited to '.emacs.d')
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 24 | ||||
| -rw-r--r-- | .emacs.d/lisp/yaml-mode.el | 456 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 76 | ||||
| -rw-r--r-- | .emacs.d/snippets/c-mode/printf | 2 | ||||
| -rw-r--r-- | .emacs.d/snippets/python-mode/print | 2 |
5 files changed, 512 insertions, 48 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index c90fa55..ef31a17 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -6,12 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | ;;; Author: Eric James Michael Ritz | 7 | ;;; Author: Eric James Michael Ritz |
| 8 | ;;; URL: https://github.com/ejmr/php-mode | 8 | ;;; URL: https://github.com/ejmr/php-mode |
| 9 | ;;; Version: 1.15.3 | 9 | ;;; Version: 1.17.0 |
| 10 | 10 | ||
| 11 | (defconst php-mode-version-number "1.15.3" | 11 | (defconst php-mode-version-number "1.17.0" |
| 12 | "PHP Mode version number.") | 12 | "PHP Mode version number.") |
| 13 | 13 | ||
| 14 | (defconst php-mode-modified "2015-03-09" | 14 | (defconst php-mode-modified "2015-06-23" |
| 15 | "PHP Mode build date.") | 15 | "PHP Mode build date.") |
| 16 | 16 | ||
| 17 | ;;; License | 17 | ;;; License |
| @@ -732,7 +732,7 @@ Implements PHP version of `beginning-of-defun-function'." | |||
| 732 | 732 | ||
| 733 | (defun php-end-of-defun (&optional arg) | 733 | (defun php-end-of-defun (&optional arg) |
| 734 | "Move the end of the ARGth PHP function from point. | 734 | "Move the end of the ARGth PHP function from point. |
| 735 | Implements PHP befsion of `end-of-defun-function' | 735 | Implements PHP version of `end-of-defun-function' |
| 736 | 736 | ||
| 737 | See `php-beginning-of-defun'." | 737 | See `php-beginning-of-defun'." |
| 738 | (interactive "p") | 738 | (interactive "p") |
| @@ -1001,8 +1001,7 @@ PHP heredoc." | |||
| 1001 | (set (make-local-variable 'syntax-propertize-function) | 1001 | (set (make-local-variable 'syntax-propertize-function) |
| 1002 | #'php-syntax-propertize-function)) | 1002 | #'php-syntax-propertize-function)) |
| 1003 | 1003 | ||
| 1004 | (setq font-lock-maximum-decoration t | 1004 | (setq imenu-generic-expression php-imenu-generic-expression) |
| 1005 | imenu-generic-expression php-imenu-generic-expression) | ||
| 1006 | 1005 | ||
| 1007 | ;; PHP vars are case-sensitive | 1006 | ;; PHP vars are case-sensitive |
| 1008 | (setq case-fold-search t) | 1007 | (setq case-fold-search t) |
| @@ -1250,7 +1249,7 @@ under which to search for files in the local documentation directory.") | |||
| 1250 | (not (assq types-list words-cache))) | 1249 | (not (assq types-list words-cache))) |
| 1251 | ;; Generate the cache on the first run, or if the types changed. | 1250 | ;; Generate the cache on the first run, or if the types changed. |
| 1252 | ;; We read the filenames matching our types list in the local | 1251 | ;; We read the filenames matching our types list in the local |
| 1253 | ;; documention directory, and extract the 'middle' component | 1252 | ;; documentation directory, and extract the 'middle' component |
| 1254 | ;; of each. e.g. "function.array-map.html" => "array_map". | 1253 | ;; of each. e.g. "function.array-map.html" => "array_map". |
| 1255 | (let* ((types-opt (regexp-opt types-list)) | 1254 | (let* ((types-opt (regexp-opt types-list)) |
| 1256 | (pattern (concat "\\`" types-opt "\\.\\(.+\\)\\.html\\'")) | 1255 | (pattern (concat "\\`" types-opt "\\.\\(.+\\)\\.html\\'")) |
| @@ -1479,9 +1478,10 @@ The output will appear in the buffer *PHP*." | |||
| 1479 | 1478 | ||
| 1480 | (defun php-string-intepolated-variable-font-lock-find (limit) | 1479 | (defun php-string-intepolated-variable-font-lock-find (limit) |
| 1481 | (while (re-search-forward php-string-interpolated-variable-regexp limit t) | 1480 | (while (re-search-forward php-string-interpolated-variable-regexp limit t) |
| 1482 | (when (php-in-string-p) | 1481 | (let ((quoted-stuff (nth 3 (syntax-ppss)))) |
| 1483 | (put-text-property (match-beginning 0) (match-end 0) | 1482 | (when (and quoted-stuff (member quoted-stuff '(?\" ?`))) |
| 1484 | 'face 'font-lock-variable-name-face))) | 1483 | (put-text-property (match-beginning 0) (match-end 0) |
| 1484 | 'face 'font-lock-variable-name-face)))) | ||
| 1485 | nil) | 1485 | nil) |
| 1486 | 1486 | ||
| 1487 | (eval-after-load 'php-mode | 1487 | (eval-after-load 'php-mode |
| @@ -1533,3 +1533,7 @@ The output will appear in the buffer *PHP*." | |||
| 1533 | (provide 'php-mode) | 1533 | (provide 'php-mode) |
| 1534 | 1534 | ||
| 1535 | ;;; php-mode.el ends here | 1535 | ;;; php-mode.el ends here |
| 1536 | |||
| 1537 | ;; Local Variables: | ||
| 1538 | ;; firestarter: ert-run-tests-interactively | ||
| 1539 | ;; End: | ||
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el new file mode 100644 index 0000000..15f3872 --- /dev/null +++ b/.emacs.d/lisp/yaml-mode.el | |||
| @@ -0,0 +1,456 @@ | |||
| 1 | ;;; yaml-mode.el --- Major mode for editing YAML files | ||
| 2 | |||
| 3 | ;; Copyright (C) 2010-2014 Yoshiki Kurihara | ||
| 4 | |||
| 5 | ;; Author: Yoshiki Kurihara <clouder@gmail.com> | ||
| 6 | ;; Marshall T. Vandegrift <llasram@gmail.com> | ||
| 7 | ;; Keywords: data yaml | ||
| 8 | ;; Version: 0.0.12 | ||
| 9 | |||
| 10 | ;; This file is not part of Emacs | ||
| 11 | |||
| 12 | ;; This file is free software; you can redistribute it and/or modify | ||
| 13 | ;; it under the terms of the GNU General Public License as published by | ||
| 14 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 15 | ;; any later version. | ||
| 16 | |||
| 17 | ;; This file is distributed in the hope that it will be useful, | ||
| 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | ;; GNU General Public License for more details. | ||
| 21 | |||
| 22 | ;; You should have received a copy of the GNU General Public License | ||
| 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to | ||
| 24 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 25 | ;; Boston, MA 02111-1307, USA. | ||
| 26 | |||
| 27 | ;;; Commentary: | ||
| 28 | |||
| 29 | ;; This is a major mode for editing files in the YAML data | ||
| 30 | ;; serialization format. It was initially developed by Yoshiki | ||
| 31 | ;; Kurihara and many features were added by Marshall Vandegrift. As | ||
| 32 | ;; YAML and Python share the fact that indentation determines | ||
| 33 | ;; structure, this mode provides indentation and indentation command | ||
| 34 | ;; behavior very similar to that of python-mode. | ||
| 35 | |||
| 36 | ;;; Installation: | ||
| 37 | |||
| 38 | ;; To install, just drop this file into a directory in your | ||
| 39 | ;; `load-path' and (optionally) byte-compile it. To automatically | ||
| 40 | ;; handle files ending in '.yml', add something like: | ||
| 41 | ;; | ||
| 42 | ;; (require 'yaml-mode) | ||
| 43 | ;; (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) | ||
| 44 | ;; | ||
| 45 | ;; to your .emacs file. | ||
| 46 | ;; | ||
| 47 | ;; Unlike python-mode, this mode follows the Emacs convention of not | ||
| 48 | ;; binding the ENTER key to `newline-and-indent'. To get this | ||
| 49 | ;; behavior, add the key definition to `yaml-mode-hook': | ||
| 50 | ;; | ||
| 51 | ;; (add-hook 'yaml-mode-hook | ||
| 52 | ;; '(lambda () | ||
| 53 | ;; (define-key yaml-mode-map "\C-m" 'newline-and-indent))) | ||
| 54 | |||
| 55 | ;;; Known Bugs: | ||
| 56 | |||
| 57 | ;; YAML is easy to write but complex to parse, and this mode doesn't | ||
| 58 | ;; even really try. Indentation and highlighting will break on | ||
| 59 | ;; abnormally complicated structures. | ||
| 60 | |||
| 61 | ;;; Code: | ||
| 62 | |||
| 63 | |||
| 64 | ;; User definable variables | ||
| 65 | |||
| 66 | ;;;###autoload | ||
| 67 | (defgroup yaml nil | ||
| 68 | "Support for the YAML serialization format" | ||
| 69 | :group 'languages | ||
| 70 | :prefix "yaml-") | ||
| 71 | |||
| 72 | (defcustom yaml-mode-hook nil | ||
| 73 | "*Hook run by `yaml-mode'." | ||
| 74 | :type 'hook | ||
| 75 | :group 'yaml) | ||
| 76 | |||
| 77 | (defcustom yaml-indent-offset 2 | ||
| 78 | "*Amount of offset per level of indentation." | ||
| 79 | :type 'integer | ||
| 80 | :group 'yaml) | ||
| 81 | |||
| 82 | (defcustom yaml-backspace-function 'backward-delete-char-untabify | ||
| 83 | "*Function called by `yaml-electric-backspace' when deleting backwards. | ||
| 84 | It will receive one argument, the numeric prefix value." | ||
| 85 | :type 'function | ||
| 86 | :group 'yaml) | ||
| 87 | |||
| 88 | (defcustom yaml-block-literal-search-lines 100 | ||
| 89 | "*Maximum number of lines to search for start of block literals." | ||
| 90 | :type 'integer | ||
| 91 | :group 'yaml) | ||
| 92 | |||
| 93 | (defcustom yaml-block-literal-electric-alist | ||
| 94 | '((?| . "") (?> . "-")) | ||
| 95 | "*Characters for which to provide electric behavior. | ||
| 96 | The association list key should be a key code and the associated value | ||
| 97 | should be a string containing additional characters to insert when | ||
| 98 | that key is pressed to begin a block literal." | ||
| 99 | :type 'alist | ||
| 100 | :group 'yaml) | ||
| 101 | |||
| 102 | (defface yaml-tab-face | ||
| 103 | '((((class color)) (:background "red" :foreground "red" :bold t)) | ||
| 104 | (t (:reverse-video t))) | ||
| 105 | "Face to use for highlighting tabs in YAML files." | ||
| 106 | :group 'faces | ||
| 107 | :group 'yaml) | ||
| 108 | |||
| 109 | (defcustom yaml-imenu-generic-expression | ||
| 110 | '((nil "^\\(:?[a-zA-Z_-]+\\):" 1)) | ||
| 111 | "The imenu regex to parse an outline of the yaml file." | ||
| 112 | :type 'string | ||
| 113 | :group 'yaml) | ||
| 114 | |||
| 115 | |||
| 116 | ;; Constants | ||
| 117 | |||
| 118 | (defconst yaml-mode-version "0.0.12" "Version of `yaml-mode'.") | ||
| 119 | |||
| 120 | (defconst yaml-blank-line-re "^ *$" | ||
| 121 | "Regexp matching a line containing only (valid) whitespace.") | ||
| 122 | |||
| 123 | (defconst yaml-directive-re "^\\(?:--- \\)? *%\\(\\w+\\)" | ||
| 124 | "Regexp matching a line contatining a YAML directive.") | ||
| 125 | |||
| 126 | (defconst yaml-document-delimiter-re "^ *\\(?:---\\|[.][.][.]\\)" | ||
| 127 | "Rexexp matching a YAML document delimiter line.") | ||
| 128 | |||
| 129 | (defconst yaml-node-anchor-alias-re "[&*][a-zA-Z0-9_-]+" | ||
| 130 | "Regexp matching a YAML node anchor or alias.") | ||
| 131 | |||
| 132 | (defconst yaml-tag-re "!!?[^ \n]+" | ||
| 133 | "Rexexp matching a YAML tag.") | ||
| 134 | |||
| 135 | (defconst yaml-bare-scalar-re | ||
| 136 | "\\(?:[^-:,#!\n{\\[ ]\\|[^#!\n{\\[ ]\\S-\\)[^#\n]*?" | ||
| 137 | "Rexexp matching a YAML bare scalar.") | ||
| 138 | |||
| 139 | (defconst yaml-hash-key-re | ||
| 140 | (concat "\\(?:^\\(?:--- \\)?\\|{\\|\\(?:[-,] +\\)+\\) *" | ||
| 141 | "\\(?:" yaml-tag-re " +\\)?" | ||
| 142 | "\\(" yaml-bare-scalar-re "\\) *:" | ||
| 143 | "\\(?: +\\|$\\)") | ||
| 144 | "Regexp matching a single YAML hash key.") | ||
| 145 | |||
| 146 | (defconst yaml-scalar-context-re | ||
| 147 | (concat "\\(?:^\\(?:--- \\)?\\|{\\|\\(?:[-,] +\\)+\\) *" | ||
| 148 | "\\(?:" yaml-bare-scalar-re " *: \\)?") | ||
| 149 | "Regexp indicating the begininng of a scalar context.") | ||
| 150 | |||
| 151 | (defconst yaml-nested-map-re | ||
| 152 | (concat ".*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$") | ||
| 153 | "Regexp matching a line beginning a YAML nested structure.") | ||
| 154 | |||
| 155 | (defconst yaml-block-literal-base-re " *[>|][-+0-9]* *\\(?:\n\\|\\'\\)" | ||
| 156 | "Regexp matching the substring start of a block literal.") | ||
| 157 | |||
| 158 | (defconst yaml-block-literal-re | ||
| 159 | (concat yaml-scalar-context-re | ||
| 160 | "\\(?:" yaml-tag-re "\\)?" | ||
| 161 | yaml-block-literal-base-re) | ||
| 162 | "Regexp matching a line beginning a YAML block literal.") | ||
| 163 | |||
| 164 | (defconst yaml-nested-sequence-re | ||
| 165 | (concat "^\\(?: *- +\\)+" | ||
| 166 | "\\(?:" yaml-bare-scalar-re " *:\\(?: +.*\\)?\\)?$") | ||
| 167 | "Regexp matching a line containing one or more nested YAML sequences.") | ||
| 168 | |||
| 169 | (defconst yaml-constant-scalars-re | ||
| 170 | (concat "\\(?:^\\|\\(?::\\|-\\|,\\|{\\|\\[\\) +\\) *" | ||
| 171 | (regexp-opt | ||
| 172 | '("~" "null" "Null" "NULL" | ||
| 173 | ".nan" ".NaN" ".NAN" | ||
| 174 | ".inf" ".Inf" ".INF" | ||
| 175 | "-.inf" "-.Inf" "-.INF" | ||
| 176 | "y" "Y" "yes" "Yes" "YES" "n" "N" "no" "No" "NO" | ||
| 177 | "true" "True" "TRUE" "false" "False" "FALSE" | ||
| 178 | "on" "On" "ON" "off" "Off" "OFF") t) | ||
| 179 | " *$") | ||
| 180 | "Regexp matching certain scalar constants in scalar context.") | ||
| 181 | |||
| 182 | |||
| 183 | ;; Mode setup | ||
| 184 | |||
| 185 | (defvar yaml-mode-map () | ||
| 186 | "Keymap used in `yaml-mode' buffers.") | ||
| 187 | (if yaml-mode-map | ||
| 188 | nil | ||
| 189 | (setq yaml-mode-map (make-sparse-keymap)) | ||
| 190 | (define-key yaml-mode-map "|" 'yaml-electric-bar-and-angle) | ||
| 191 | (define-key yaml-mode-map ">" 'yaml-electric-bar-and-angle) | ||
| 192 | (define-key yaml-mode-map "-" 'yaml-electric-dash-and-dot) | ||
| 193 | (define-key yaml-mode-map "." 'yaml-electric-dash-and-dot) | ||
| 194 | (define-key yaml-mode-map [backspace] 'yaml-electric-backspace)) | ||
| 195 | |||
| 196 | (defvar yaml-mode-syntax-table nil | ||
| 197 | "Syntax table in use in `yaml-mode' buffers.") | ||
| 198 | (if yaml-mode-syntax-table | ||
| 199 | nil | ||
| 200 | (setq yaml-mode-syntax-table (make-syntax-table)) | ||
| 201 | (modify-syntax-entry ?\' "\"" yaml-mode-syntax-table) | ||
| 202 | (modify-syntax-entry ?\" "\"" yaml-mode-syntax-table) | ||
| 203 | (modify-syntax-entry ?# "<" yaml-mode-syntax-table) | ||
| 204 | (modify-syntax-entry ?\n ">" yaml-mode-syntax-table) | ||
| 205 | (modify-syntax-entry ?\\ "\\" yaml-mode-syntax-table) | ||
| 206 | (modify-syntax-entry ?- "w" yaml-mode-syntax-table) | ||
| 207 | (modify-syntax-entry ?_ "_" yaml-mode-syntax-table) | ||
| 208 | (modify-syntax-entry ?\( "." yaml-mode-syntax-table) | ||
| 209 | (modify-syntax-entry ?\) "." yaml-mode-syntax-table) | ||
| 210 | (modify-syntax-entry ?\{ "(}" yaml-mode-syntax-table) | ||
| 211 | (modify-syntax-entry ?\} "){" yaml-mode-syntax-table) | ||
| 212 | (modify-syntax-entry ?\[ "(]" yaml-mode-syntax-table) | ||
| 213 | (modify-syntax-entry ?\] ")[" yaml-mode-syntax-table)) | ||
| 214 | |||
| 215 | ;;;###autoload | ||
| 216 | (define-derived-mode yaml-mode fundamental-mode "YAML" | ||
| 217 | "Simple mode to edit YAML. | ||
| 218 | |||
| 219 | \\{yaml-mode-map}" | ||
| 220 | :syntax-table yaml-mode-syntax-table | ||
| 221 | (set (make-local-variable 'comment-start) "# ") | ||
| 222 | (set (make-local-variable 'comment-start-skip) "#+ *") | ||
| 223 | (set (make-local-variable 'indent-line-function) 'yaml-indent-line) | ||
| 224 | (set (make-local-variable 'indent-tabs-mode) nil) | ||
| 225 | (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph) | ||
| 226 | (set (make-local-variable 'font-lock-defaults) | ||
| 227 | '(yaml-font-lock-keywords | ||
| 228 | nil nil nil nil | ||
| 229 | (font-lock-syntactic-keywords . yaml-font-lock-syntactic-keywords))) | ||
| 230 | (if (fboundp 'font-lock-flush) | ||
| 231 | (font-lock-flush) | ||
| 232 | (with-no-warnings | ||
| 233 | (font-lock-fontify-buffer)))) | ||
| 234 | |||
| 235 | |||
| 236 | ;; Font-lock support | ||
| 237 | |||
| 238 | (defvar yaml-font-lock-keywords | ||
| 239 | (list | ||
| 240 | (cons yaml-constant-scalars-re '(1 font-lock-constant-face)) | ||
| 241 | (cons yaml-tag-re '(0 font-lock-type-face)) | ||
| 242 | (cons yaml-node-anchor-alias-re '(0 font-lock-function-name-face)) | ||
| 243 | (cons yaml-hash-key-re '(1 font-lock-variable-name-face)) | ||
| 244 | (cons yaml-document-delimiter-re '(0 font-lock-comment-face)) | ||
| 245 | (cons yaml-directive-re '(1 font-lock-builtin-face)) | ||
| 246 | '(yaml-font-lock-block-literals 0 font-lock-string-face) | ||
| 247 | '("^[\t]+" 0 'yaml-tab-face t)) | ||
| 248 | "Additional expressions to highlight in YAML mode.") | ||
| 249 | |||
| 250 | (defvar yaml-font-lock-syntactic-keywords | ||
| 251 | (list '(yaml-syntactic-block-literals 0 ".")) | ||
| 252 | "Additional syntax features to highlight in YAML mode.") | ||
| 253 | |||
| 254 | |||
| 255 | (defun yaml-font-lock-block-literals (bound) | ||
| 256 | "Find lines within block literals. | ||
| 257 | Find the next line of the first (if any) block literal after point and | ||
| 258 | prior to BOUND. Returns the beginning and end of the block literal | ||
| 259 | line in the match data, as consumed by `font-lock-keywords' matcher | ||
| 260 | functions. The function begins by searching backwards to determine | ||
| 261 | whether or not the current line is within a block literal. This could | ||
| 262 | be time-consuming in large buffers, so the number of lines searched is | ||
| 263 | artificially limitted to the value of | ||
| 264 | `yaml-block-literal-search-lines'." | ||
| 265 | (if (eolp) (goto-char (1+ (point)))) | ||
| 266 | (unless (or (eobp) (>= (point) bound)) | ||
| 267 | (let ((begin (point)) | ||
| 268 | (end (min (1+ (point-at-eol)) bound))) | ||
| 269 | (goto-char (point-at-bol)) | ||
| 270 | (while (and (looking-at yaml-blank-line-re) (not (bobp))) | ||
| 271 | (forward-line -1)) | ||
| 272 | (let ((nlines yaml-block-literal-search-lines) | ||
| 273 | (min-level (current-indentation))) | ||
| 274 | (forward-line -1) | ||
| 275 | (while (and (/= nlines 0) | ||
| 276 | (/= min-level 0) | ||
| 277 | (not (looking-at yaml-block-literal-re)) | ||
| 278 | (not (bobp))) | ||
| 279 | (set 'nlines (1- nlines)) | ||
| 280 | (unless (looking-at yaml-blank-line-re) | ||
| 281 | (set 'min-level (min min-level (current-indentation)))) | ||
| 282 | (forward-line -1)) | ||
| 283 | (cond | ||
| 284 | ((and (< (current-indentation) min-level) | ||
| 285 | (looking-at yaml-block-literal-re)) | ||
| 286 | (goto-char end) (set-match-data (list begin end)) t) | ||
| 287 | ((progn | ||
| 288 | (goto-char begin) | ||
| 289 | (re-search-forward (concat yaml-block-literal-re | ||
| 290 | " *\\(.*\\)\n") | ||
| 291 | bound t)) | ||
| 292 | (set-match-data (nthcdr 2 (match-data))) t)))))) | ||
| 293 | |||
| 294 | (defun yaml-syntactic-block-literals (bound) | ||
| 295 | "Find quote characters within block literals. | ||
| 296 | Finds the first quote character within a block literal (if any) after | ||
| 297 | point and prior to BOUND. Returns the position of the quote character | ||
| 298 | in the match data, as consumed by matcher functions in | ||
| 299 | `font-lock-syntactic-keywords'. This allows the mode to treat ['\"] | ||
| 300 | characters in block literals as punctuation syntax instead of string | ||
| 301 | syntax, preventing unmatched quotes in block literals from painting | ||
| 302 | the entire buffer in `font-lock-string-face'." | ||
| 303 | (let ((found nil)) | ||
| 304 | (while (and (not found) | ||
| 305 | (/= (point) bound) | ||
| 306 | (yaml-font-lock-block-literals bound)) | ||
| 307 | (let ((begin (match-beginning 0)) (end (match-end 0))) | ||
| 308 | (goto-char begin) | ||
| 309 | (cond | ||
| 310 | ((re-search-forward "['\"]" end t) (setq found t)) | ||
| 311 | ((goto-char end))))) | ||
| 312 | found)) | ||
| 313 | |||
| 314 | |||
| 315 | ;; Indentation and electric keys | ||
| 316 | |||
| 317 | (defun yaml-compute-indentation () | ||
| 318 | "Calculate the maximum sensible indentation for the current line." | ||
| 319 | (save-excursion | ||
| 320 | (beginning-of-line) | ||
| 321 | (if (looking-at yaml-document-delimiter-re) 0 | ||
| 322 | (forward-line -1) | ||
| 323 | (while (and (looking-at yaml-blank-line-re) | ||
| 324 | (> (point) (point-min))) | ||
| 325 | (forward-line -1)) | ||
| 326 | (+ (current-indentation) | ||
| 327 | (if (looking-at yaml-nested-map-re) yaml-indent-offset 0) | ||
| 328 | (if (looking-at yaml-nested-sequence-re) yaml-indent-offset 0) | ||
| 329 | (if (looking-at yaml-block-literal-re) yaml-indent-offset 0))))) | ||
| 330 | |||
| 331 | (defun yaml-indent-line () | ||
| 332 | "Indent the current line. | ||
| 333 | The first time this command is used, the line will be indented to the | ||
| 334 | maximum sensible indentation. Each immediately subsequent usage will | ||
| 335 | back-dent the line by `yaml-indent-offset' spaces. On reaching column | ||
| 336 | 0, it will cycle back to the maximum sensible indentation." | ||
| 337 | (interactive "*") | ||
| 338 | (let ((ci (current-indentation)) | ||
| 339 | (cc (current-column)) | ||
| 340 | (need (yaml-compute-indentation))) | ||
| 341 | (save-excursion | ||
| 342 | (beginning-of-line) | ||
| 343 | (delete-horizontal-space) | ||
| 344 | (if (and (equal last-command this-command) (/= ci 0)) | ||
| 345 | (indent-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset)) | ||
| 346 | (indent-to need))) | ||
| 347 | (if (< (current-column) (current-indentation)) | ||
| 348 | (forward-to-indentation 0)))) | ||
| 349 | |||
| 350 | (defun yaml-electric-backspace (arg) | ||
| 351 | "Delete characters or back-dent the current line. | ||
| 352 | If invoked following only whitespace on a line, will back-dent to the | ||
| 353 | immediately previous multiple of `yaml-indent-offset' spaces." | ||
| 354 | (interactive "*p") | ||
| 355 | (if (or (/= (current-indentation) (current-column)) (bolp)) | ||
| 356 | (funcall yaml-backspace-function arg) | ||
| 357 | (let ((ci (current-column))) | ||
| 358 | (beginning-of-line) | ||
| 359 | (delete-horizontal-space) | ||
| 360 | (indent-to (* (/ (- ci (* arg yaml-indent-offset)) | ||
| 361 | yaml-indent-offset) | ||
| 362 | yaml-indent-offset))))) | ||
| 363 | |||
| 364 | (defun yaml-electric-bar-and-angle (arg) | ||
| 365 | "Insert the bound key and possibly begin a block literal. | ||
| 366 | Inserts the bound key. If inserting the bound key causes the current | ||
| 367 | line to match the initial line of a block literal, then inserts the | ||
| 368 | matching string from `yaml-block-literal-electric-alist', a newline, | ||
| 369 | and indents appropriately." | ||
| 370 | (interactive "*P") | ||
| 371 | (self-insert-command (prefix-numeric-value arg)) | ||
| 372 | (let ((extra-chars | ||
| 373 | (assoc last-command-event | ||
| 374 | yaml-block-literal-electric-alist))) | ||
| 375 | (cond | ||
| 376 | ((and extra-chars (not arg) (eolp) | ||
| 377 | (save-excursion | ||
| 378 | (beginning-of-line) | ||
| 379 | (looking-at yaml-block-literal-re))) | ||
| 380 | (insert (cdr extra-chars)) | ||
| 381 | (newline-and-indent))))) | ||
| 382 | |||
| 383 | (defun yaml-electric-dash-and-dot (arg) | ||
| 384 | "Insert the bound key and possibly de-dent line. | ||
| 385 | Inserts the bound key. If inserting the bound key causes the current | ||
| 386 | line to match a document delimiter, de-dent the line to the left | ||
| 387 | margin." | ||
| 388 | (interactive "*P") | ||
| 389 | (self-insert-command (prefix-numeric-value arg)) | ||
| 390 | (save-excursion | ||
| 391 | (beginning-of-line) | ||
| 392 | (if (and (not arg) (looking-at yaml-document-delimiter-re)) | ||
| 393 | (delete-horizontal-space)))) | ||
| 394 | |||
| 395 | (defun yaml-narrow-to-block-literal () | ||
| 396 | "Narrow the buffer to block literal if the point is in it, | ||
| 397 | otherwise do nothing." | ||
| 398 | (interactive) | ||
| 399 | (save-excursion | ||
| 400 | (goto-char (point-at-bol)) | ||
| 401 | (while (and (looking-at-p yaml-blank-line-re) (not (bobp))) | ||
| 402 | (forward-line -1)) | ||
| 403 | (let ((nlines yaml-block-literal-search-lines) | ||
| 404 | (min-level (current-indentation)) | ||
| 405 | beg) | ||
| 406 | (forward-line -1) | ||
| 407 | (while (and (/= nlines 0) | ||
| 408 | (/= min-level 0) | ||
| 409 | (not (looking-at-p yaml-block-literal-re)) | ||
| 410 | (not (bobp))) | ||
| 411 | (set 'nlines (1- nlines)) | ||
| 412 | (unless (looking-at-p yaml-blank-line-re) | ||
| 413 | (set 'min-level (min min-level (current-indentation)))) | ||
| 414 | (forward-line -1)) | ||
| 415 | (when (and (< (current-indentation) min-level) | ||
| 416 | (looking-at-p yaml-block-literal-re)) | ||
| 417 | (set 'min-level (current-indentation)) | ||
| 418 | (forward-line) | ||
| 419 | (setq beg (point)) | ||
| 420 | (while (and (not (eobp)) | ||
| 421 | (or (looking-at-p yaml-blank-line-re) | ||
| 422 | (> (current-indentation) min-level))) | ||
| 423 | (forward-line)) | ||
| 424 | (narrow-to-region beg (point)))))) | ||
| 425 | |||
| 426 | (defun yaml-fill-paragraph (&optional justify region) | ||
| 427 | "Fill paragraph. | ||
| 428 | This behaves as `fill-paragraph' except that filling does not | ||
| 429 | cross boundaries of block literals." | ||
| 430 | (interactive "*P") | ||
| 431 | (save-restriction | ||
| 432 | (yaml-narrow-to-block-literal) | ||
| 433 | (let ((fill-paragraph-function nil)) | ||
| 434 | (fill-paragraph justify region)))) | ||
| 435 | |||
| 436 | (defun yaml-set-imenu-generic-expression () | ||
| 437 | (make-local-variable 'imenu-generic-expression) | ||
| 438 | (make-local-variable 'imenu-create-index-function) | ||
| 439 | (setq imenu-create-index-function 'imenu-default-create-index-function) | ||
| 440 | (setq imenu-generic-expression yaml-imenu-generic-expression)) | ||
| 441 | |||
| 442 | (add-hook 'yaml-mode-hook 'yaml-set-imenu-generic-expression) | ||
| 443 | |||
| 444 | |||
| 445 | (defun yaml-mode-version () | ||
| 446 | "Diplay version of `yaml-mode'." | ||
| 447 | (interactive) | ||
| 448 | (message "yaml-mode %s" yaml-mode-version) | ||
| 449 | yaml-mode-version) | ||
| 450 | |||
| 451 | ;;;###autoload | ||
| 452 | (add-to-list 'auto-mode-alist '("\\.e?ya?ml$" . yaml-mode)) | ||
| 453 | |||
| 454 | (provide 'yaml-mode) | ||
| 455 | |||
| 456 | ;;; yaml-mode.el ends here | ||
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 305bb95..1f6c7de 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -725,7 +725,7 @@ defined direct keybindings to the command | |||
| 725 | yas--direct-keymaps)) | 725 | yas--direct-keymaps)) |
| 726 | yas--tables)) | 726 | yas--tables)) |
| 727 | 727 | ||
| 728 | (defun yas--modes-to-activate () | 728 | (defun yas--modes-to-activate (&optional mode) |
| 729 | "Compute list of mode symbols that are active for `yas-expand' | 729 | "Compute list of mode symbols that are active for `yas-expand' |
| 730 | and friends." | 730 | and friends." |
| 731 | (let (dfs) | 731 | (let (dfs) |
| @@ -740,8 +740,10 @@ and friends." | |||
| 740 | (not (memq neighbour explored)) | 740 | (not (memq neighbour explored)) |
| 741 | (symbolp neighbour)) | 741 | (symbolp neighbour)) |
| 742 | append (funcall dfs neighbour explored))))) | 742 | append (funcall dfs neighbour explored))))) |
| 743 | (remove-duplicates (append yas--extra-modes | 743 | (remove-duplicates (if mode |
| 744 | (funcall dfs major-mode))))) | 744 | (funcall dfs mode) |
| 745 | (append yas--extra-modes | ||
| 746 | (funcall dfs major-mode)))))) | ||
| 745 | 747 | ||
| 746 | (defvar yas-minor-mode-hook nil | 748 | (defvar yas-minor-mode-hook nil |
| 747 | "Hook run when `yas-minor-mode' is turned on.") | 749 | "Hook run when `yas-minor-mode' is turned on.") |
| @@ -1333,15 +1335,17 @@ return an expression that when evaluated will issue an error." | |||
| 1333 | yas--direct-keymaps)) | 1335 | yas--direct-keymaps)) |
| 1334 | table)) | 1336 | table)) |
| 1335 | 1337 | ||
| 1336 | (defun yas--get-snippet-tables () | 1338 | (defun yas--get-snippet-tables (&optional mode) |
| 1337 | "Get snippet tables for current buffer. | 1339 | "Get snippet tables for MODE. |
| 1340 | |||
| 1341 | MODE defaults to the current buffer's `major-mode'. | ||
| 1338 | 1342 | ||
| 1339 | Return a list of `yas--table' objects. The list of modes to | 1343 | Return a list of `yas--table' objects. The list of modes to |
| 1340 | consider is returned by `yas--modes-to-activate'" | 1344 | consider is returned by `yas--modes-to-activate'" |
| 1341 | (remove nil | 1345 | (remove nil |
| 1342 | (mapcar #'(lambda (name) | 1346 | (mapcar #'(lambda (name) |
| 1343 | (gethash name yas--tables)) | 1347 | (gethash name yas--tables)) |
| 1344 | (yas--modes-to-activate)))) | 1348 | (yas--modes-to-activate mode)))) |
| 1345 | 1349 | ||
| 1346 | (defun yas--menu-keymap-get-create (mode &optional parents) | 1350 | (defun yas--menu-keymap-get-create (mode &optional parents) |
| 1347 | "Get or create the menu keymap for MODE and its PARENTS. | 1351 | "Get or create the menu keymap for MODE and its PARENTS. |
| @@ -1661,33 +1665,16 @@ file with the same uuid would replace the previous snippet. | |||
| 1661 | You can use `yas--parse-template' to return such lists based on | 1665 | You can use `yas--parse-template' to return such lists based on |
| 1662 | the current buffers contents." | 1666 | the current buffers contents." |
| 1663 | (if yas--creating-compiled-snippets | 1667 | (if yas--creating-compiled-snippets |
| 1664 | (progn | 1668 | (let ((print-length nil)) |
| 1665 | (insert ";;; Snippet definitions:\n;;;\n") | 1669 | (insert ";;; Snippet definitions:\n;;;\n") |
| 1666 | (let ((literal-snippets (list)) | 1670 | (dolist (snippet snippets) |
| 1667 | (print-length nil)) | 1671 | ;; We omit file because the snippet will be loaded from |
| 1668 | (dolist (snippet snippets) | 1672 | ;; the compiled file instead, so deleting or changing |
| 1669 | (let ((key (nth 0 snippet)) | 1673 | ;; the original won't have any effect. |
| 1670 | (template-content (nth 1 snippet)) | 1674 | (setcar (nthcdr 6 snippet) nil)) |
| 1671 | (name (nth 2 snippet)) | 1675 | (insert (pp-to-string |
| 1672 | (condition (nth 3 snippet)) | 1676 | `(yas-define-snippets ',mode ',snippets))) |
| 1673 | (group (nth 4 snippet)) | 1677 | (insert "\n\n")) |
| 1674 | (expand-env (nth 5 snippet)) | ||
| 1675 | (file nil) ;; omit on purpose | ||
| 1676 | (binding (nth 7 snippet)) | ||
| 1677 | (uuid (nth 8 snippet))) | ||
| 1678 | (push `(,key | ||
| 1679 | ,template-content | ||
| 1680 | ,name | ||
| 1681 | ,condition | ||
| 1682 | ,group | ||
| 1683 | ,expand-env | ||
| 1684 | ,file | ||
| 1685 | ,binding | ||
| 1686 | ,uuid) | ||
| 1687 | literal-snippets))) | ||
| 1688 | (insert (pp-to-string | ||
| 1689 | `(yas-define-snippets ',mode ',literal-snippets))) | ||
| 1690 | (insert "\n\n"))) | ||
| 1691 | ;; Normal case. | 1678 | ;; Normal case. |
| 1692 | (let ((snippet-table (yas--table-get-create mode)) | 1679 | (let ((snippet-table (yas--table-get-create mode)) |
| 1693 | (template nil)) | 1680 | (template nil)) |
| @@ -2305,6 +2292,24 @@ Honours `yas-choose-tables-first', `yas-choose-keys-first' and | |||
| 2305 | (remove-duplicates (mapcan #'yas--table-templates tables) | 2292 | (remove-duplicates (mapcan #'yas--table-templates tables) |
| 2306 | :test #'equal)))) | 2293 | :test #'equal)))) |
| 2307 | 2294 | ||
| 2295 | (defun yas-lookup-snippet (name &optional mode noerror) | ||
| 2296 | "Get the snippet content for the snippet NAME in MODE's tables. | ||
| 2297 | |||
| 2298 | MODE defaults to the current buffer's `major-mode'. If NOERROR | ||
| 2299 | is non-nil, then don't signal an error if there isn't any snippet | ||
| 2300 | called NAME. | ||
| 2301 | |||
| 2302 | Honours `yas-buffer-local-condition'." | ||
| 2303 | (let* ((yas-choose-tables-first nil) ; avoid prompts | ||
| 2304 | (yas-choose-keys-first nil) | ||
| 2305 | (snippet (cl-find name (yas--all-templates | ||
| 2306 | (yas--get-snippet-tables mode)) | ||
| 2307 | :key #'yas--template-name :test #'string=))) | ||
| 2308 | (cond | ||
| 2309 | (snippet (yas--template-content snippet)) | ||
| 2310 | (noerror nil) | ||
| 2311 | (t (error "No snippet named: %s" name))))) | ||
| 2312 | |||
| 2308 | (defun yas-insert-snippet (&optional no-condition) | 2313 | (defun yas-insert-snippet (&optional no-condition) |
| 2309 | "Choose a snippet to expand, pop-up a list of choices according | 2314 | "Choose a snippet to expand, pop-up a list of choices according |
| 2310 | to `yas-prompt-functions'. | 2315 | to `yas-prompt-functions'. |
| @@ -2562,10 +2567,9 @@ and `kill-buffer' instead." | |||
| 2562 | ;; | 2567 | ;; |
| 2563 | (not (yas--template-file yas--editing-template)) | 2568 | (not (yas--template-file yas--editing-template)) |
| 2564 | (not (file-writable-p (yas--template-file yas--editing-template))) | 2569 | (not (file-writable-p (yas--template-file yas--editing-template))) |
| 2565 | (and (listp yas-snippet-dirs) | 2570 | (and (cdr-safe yas-snippet-dirs) |
| 2566 | (second yas-snippet-dirs) | 2571 | (not (string-prefix-p (expand-file-name (car yas-snippet-dirs)) |
| 2567 | (not (string-match (expand-file-name (first yas-snippet-dirs)) | 2572 | (yas--template-file yas--editing-template))))) |
| 2568 | (yas--template-file yas--editing-template))))) | ||
| 2569 | (y-or-n-p (yas--format "Looks like a library or new snippet. Save to new file? "))) | 2573 | (y-or-n-p (yas--format "Looks like a library or new snippet. Save to new file? "))) |
| 2570 | (let* ((option (first (yas--guess-snippet-directories (yas--template-table yas--editing-template)))) | 2574 | (let* ((option (first (yas--guess-snippet-directories (yas--template-table yas--editing-template)))) |
| 2571 | (chosen (and option | 2575 | (chosen (and option |
diff --git a/.emacs.d/snippets/c-mode/printf b/.emacs.d/snippets/c-mode/printf index ccc788c..ec1567e 100644 --- a/.emacs.d/snippets/c-mode/printf +++ b/.emacs.d/snippets/c-mode/printf | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # -*- mode: snippet -*- | 1 | # -*- mode: snippet -*- |
| 2 | # name: printf | 2 | # name: printf |
| 3 | # key: pr | 3 | # key: p |
| 4 | # -- | 4 | # -- |
| 5 | printf("${1:format string}"${2: ,a0,a1}); \ No newline at end of file | 5 | printf("${1:format string}"${2: ,a0,a1}); \ No newline at end of file |
diff --git a/.emacs.d/snippets/python-mode/print b/.emacs.d/snippets/python-mode/print index cc1c797..d9fb14a 100644 --- a/.emacs.d/snippets/python-mode/print +++ b/.emacs.d/snippets/python-mode/print | |||
| @@ -2,4 +2,4 @@ | |||
| 2 | # name: print | 2 | # name: print |
| 3 | # key: p | 3 | # key: p |
| 4 | # -- | 4 | # -- |
| 5 | print($0) \ No newline at end of file | 5 | print('$0') \ No newline at end of file |
