diff options
| author | Simeon Simeonov | 2022-11-20 18:32:51 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2022-11-20 18:32:51 +0100 |
| commit | fbe17a9961043c66e43b46aa524b35593da78bf4 (patch) | |
| tree | 12dfac14a3bd9262203180e6e33d6facf8c73da3 | |
| parent | fb01ddbc487794a2d53fb13733dc03f73dee37ed (diff) | |
Add nginx-mode.el and update markdown-mode.el
| -rw-r--r-- | .emacs | 7 | ||||
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 4 | ||||
| -rw-r--r-- | .emacs.d/lisp/nginx-mode.el | 201 |
3 files changed, 210 insertions, 2 deletions
| @@ -109,6 +109,7 @@ | |||
| 109 | ;;(autoload 'php-mode "php-mode" "Mode for editing PHP source files") | 109 | ;;(autoload 'php-mode "php-mode" "Mode for editing PHP source files") |
| 110 | ;;(add-to-list 'auto-mode-alist '("\\.\\(inc\\|php[s34]?\\)" . php-mode)) | 110 | ;;(add-to-list 'auto-mode-alist '("\\.\\(inc\\|php[s34]?\\)" . php-mode)) |
| 111 | 111 | ||
| 112 | |||
| 112 | ;; Lua | 113 | ;; Lua |
| 113 | (autoload 'lua-mode "lua-mode" "Lua editing mode." t) | 114 | (autoload 'lua-mode "lua-mode" "Lua editing mode." t) |
| 114 | (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode)) | 115 | (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode)) |
| @@ -128,11 +129,17 @@ | |||
| 128 | "Major mode for editing GitHub Flavored Markdown files" t) | 129 | "Major mode for editing GitHub Flavored Markdown files" t) |
| 129 | (add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode)) | 130 | (add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode)) |
| 130 | 131 | ||
| 132 | |||
| 131 | ;; YAML | 133 | ;; YAML |
| 132 | (require 'yaml-mode) | 134 | (require 'yaml-mode) |
| 133 | (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) | 135 | (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) |
| 134 | 136 | ||
| 137 | |||
| 135 | ;; yasnippet | 138 | ;; yasnippet |
| 136 | (require 'yasnippet) | 139 | (require 'yasnippet) |
| 137 | (yas-global-mode 1) | 140 | (yas-global-mode 1) |
| 138 | (yas/load-directory "~/.emacs.d/snippets") | 141 | (yas/load-directory "~/.emacs.d/snippets") |
| 142 | |||
| 143 | |||
| 144 | ;; nginx | ||
| 145 | ;; (require 'nginx-mode) | ||
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index ae6dc47..4e59afa 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;; Author: Jason R. Blevins <jblevins@xbeta.org> | 6 | ;; Author: Jason R. Blevins <jblevins@xbeta.org> |
| 7 | ;; Maintainer: Jason R. Blevins <jblevins@xbeta.org> | 7 | ;; Maintainer: Jason R. Blevins <jblevins@xbeta.org> |
| 8 | ;; Created: May 24, 2007 | 8 | ;; Created: May 24, 2007 |
| 9 | ;; Version: 2.6-dev | 9 | ;; Version: 2.6-alpha |
| 10 | ;; Package-Requires: ((emacs "26.1")) | 10 | ;; Package-Requires: ((emacs "26.1")) |
| 11 | ;; Keywords: Markdown, GitHub Flavored Markdown, itex | 11 | ;; Keywords: Markdown, GitHub Flavored Markdown, itex |
| 12 | ;; URL: https://jblevins.org/projects/markdown-mode/ | 12 | ;; URL: https://jblevins.org/projects/markdown-mode/ |
| @@ -55,7 +55,7 @@ | |||
| 55 | 55 | ||
| 56 | ;;; Constants ================================================================= | 56 | ;;; Constants ================================================================= |
| 57 | 57 | ||
| 58 | (defconst markdown-mode-version "2.6-dev" | 58 | (defconst markdown-mode-version "2.6-alpha" |
| 59 | "Markdown mode version number.") | 59 | "Markdown mode version number.") |
| 60 | 60 | ||
| 61 | (defconst markdown-output-buffer-name "*markdown-output*" | 61 | (defconst markdown-output-buffer-name "*markdown-output*" |
diff --git a/.emacs.d/lisp/nginx-mode.el b/.emacs.d/lisp/nginx-mode.el new file mode 100644 index 0000000..b01367c --- /dev/null +++ b/.emacs.d/lisp/nginx-mode.el | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | ;;; nginx-mode.el --- major mode for editing nginx config files | ||
| 2 | |||
| 3 | ;; Copyright 2010 Andrew J Cosgriff <andrew@cosgriff.name> | ||
| 4 | |||
| 5 | ;; Author: Andrew J Cosgriff <andrew@cosgriff.name> | ||
| 6 | ;; Maintainer: Andrew J Cosgriff <andrew@cosgriff.name> | ||
| 7 | ;; Created: 15 Oct 2010 | ||
| 8 | ;; Version: 1.1.9 | ||
| 9 | ;; Keywords: languages, nginx | ||
| 10 | |||
| 11 | ;; available from http://github.com/ajc/nginx-mode | ||
| 12 | |||
| 13 | ;; This program is free software; you can redistribute it and/or modify | ||
| 14 | ;; it under the terms of the GNU General Public License as published by | ||
| 15 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 16 | ;; any later version. | ||
| 17 | ;; | ||
| 18 | ;; This program is distributed in the hope that it will be useful, | ||
| 19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | ;; GNU General Public License for more details. | ||
| 22 | ;; | ||
| 23 | ;; You should have received a copy of the GNU General Public License | ||
| 24 | ;; along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 25 | |||
| 26 | ;;; Commentary: | ||
| 27 | |||
| 28 | ;; This is a quick mode for editing Nginx config files, as I didn't find | ||
| 29 | ;; anything else around that did quite this much. | ||
| 30 | |||
| 31 | ;; Many thanks to the authors of puppet-mode.el, from where I found a | ||
| 32 | ;; useful indentation function that I've modified to suit this situation. | ||
| 33 | |||
| 34 | ;; Put this file into your load-path and the following into your ~/.emacs: | ||
| 35 | ;; (require 'nginx-mode) | ||
| 36 | |||
| 37 | ;;; Code: | ||
| 38 | |||
| 39 | |||
| 40 | ;;;;########################################################################## | ||
| 41 | ;;;; User Options, Variables | ||
| 42 | ;;;;########################################################################## | ||
| 43 | |||
| 44 | (defcustom nginx-indent-level 4 | ||
| 45 | "*Indentation of Nginx statements." | ||
| 46 | :type 'integer :group 'nginx) | ||
| 47 | |||
| 48 | (defcustom nginx-indent-tabs-mode nil | ||
| 49 | "*Indentation can insert tabs in nginx mode if this is non-nil." | ||
| 50 | :type 'boolean :group 'nginx) | ||
| 51 | |||
| 52 | (defvar nginx-mode-syntax-table | ||
| 53 | (let ((table (make-syntax-table))) | ||
| 54 | (modify-syntax-entry ?# "< b" table) | ||
| 55 | (modify-syntax-entry ?\n "> b" table) | ||
| 56 | table) | ||
| 57 | "Syntax table for `nginx-mode'.") | ||
| 58 | |||
| 59 | (defvar nginx-font-lock-keywords | ||
| 60 | (list '("^\\([ \t]+\\)?\\([A-Za-z09_]+\\)" 2 font-lock-keyword-face t) | ||
| 61 | ;; uncomment the next one if you want your eyes to bleed | ||
| 62 | ;; (it'll highlight parentheses and curly braces) | ||
| 63 | ;;'("\\(\{\\|\}\\|\(\\|\)\\)" . font-lock-pseudo-keyword-face) | ||
| 64 | '("^\\([ \t]+\\)?rewrite[ \t]+.+[ \t]+\\(permanent\\|redirect\\|break\\|last\\);$" 2 font-lock-function-name-face) | ||
| 65 | '("\\(\$[0-9]+\\)[^0-9]" 1 font-lock-constant-face) | ||
| 66 | '("\$[A-Za-z0-9_\-]+" . font-lock-variable-name-face) | ||
| 67 | '("[ \t]+\\(on\\|off\\);$" 1 font-lock-constant-face) | ||
| 68 | '("[A-Za-z0-9_\-]+\\([ \t]+[^ \t\n]+\\)?[ \t]+\\([^ \t\n]+\\)[ \t]+{" 2 font-lock-function-name-face))) | ||
| 69 | |||
| 70 | |||
| 71 | ;;;;########################################################################## | ||
| 72 | ;;;; Code | ||
| 73 | ;;;;########################################################################## | ||
| 74 | |||
| 75 | (defun nginx-block-indent () | ||
| 76 | "If point is in a block, return the indentation of the first line of that | ||
| 77 | block (the line containing the opening brace). Used to set the indentation | ||
| 78 | of the closing brace of a block." | ||
| 79 | (save-excursion | ||
| 80 | (save-match-data | ||
| 81 | (let ((opoint (point)) | ||
| 82 | (apoint (search-backward "{" nil t))) | ||
| 83 | (when apoint | ||
| 84 | ;; This is a bit of a hack and doesn't allow for strings. We really | ||
| 85 | ;; want to parse by sexps at some point. | ||
| 86 | (let ((close-braces (count-matches "}" apoint opoint)) | ||
| 87 | (open-braces 0)) | ||
| 88 | (while (and apoint (> close-braces open-braces)) | ||
| 89 | (setq apoint (search-backward "{" nil t)) | ||
| 90 | (when apoint | ||
| 91 | (setq close-braces (count-matches "}" apoint opoint)) | ||
| 92 | (setq open-braces (1+ open-braces))))) | ||
| 93 | (if apoint | ||
| 94 | (current-indentation) | ||
| 95 | nil)))))) | ||
| 96 | |||
| 97 | |||
| 98 | (defun nginx-comment-line-p () | ||
| 99 | "Return non-nil iff this line is a comment." | ||
| 100 | (save-excursion | ||
| 101 | (save-match-data | ||
| 102 | (beginning-of-line) | ||
| 103 | (looking-at "^\\s-*#")))) | ||
| 104 | |||
| 105 | (defun nginx-indent-line () | ||
| 106 | "Indent current line as nginx code." | ||
| 107 | (interactive) | ||
| 108 | (beginning-of-line) | ||
| 109 | (if (bobp) | ||
| 110 | (indent-line-to 0) ; First line is always non-indented | ||
| 111 | (let ((not-indented t) | ||
| 112 | (block-indent (nginx-block-indent)) | ||
| 113 | cur-indent) | ||
| 114 | (cond | ||
| 115 | ((and (looking-at "^\\s-*}\\s-*$") block-indent) | ||
| 116 | ;; This line contains a closing brace and we're at the inner | ||
| 117 | ;; block, so we should indent it matching the indentation of | ||
| 118 | ;; the opening brace of the block. | ||
| 119 | (setq cur-indent block-indent)) | ||
| 120 | (t | ||
| 121 | ;; Otherwise, we did not start on a block-ending-only line. | ||
| 122 | (save-excursion | ||
| 123 | ;; Iterate backwards until we find an indentation hint | ||
| 124 | (while not-indented | ||
| 125 | (forward-line -1) | ||
| 126 | (cond | ||
| 127 | ;; Comment lines are ignored unless we're at the start of the | ||
| 128 | ;; buffer. | ||
| 129 | ((nginx-comment-line-p) | ||
| 130 | (if (bobp) | ||
| 131 | (setq not-indented nil))) | ||
| 132 | |||
| 133 | ;; Brace or paren on a line by itself will already be indented to | ||
| 134 | ;; the right level, so we can cheat and stop there. | ||
| 135 | ((looking-at "^\\s-*}\\s-*") | ||
| 136 | (setq cur-indent (current-indentation)) | ||
| 137 | (setq not-indented nil)) | ||
| 138 | |||
| 139 | ;; Indent by one level more than the start of our block. We lose | ||
| 140 | ;; if there is more than one block opened and closed on the same | ||
| 141 | ;; line but it's still unbalanced; hopefully people don't do that. | ||
| 142 | ((looking-at "^.*{[^\n}]*$") | ||
| 143 | (setq cur-indent (+ (current-indentation) nginx-indent-level)) | ||
| 144 | (setq not-indented nil)) | ||
| 145 | |||
| 146 | ;; Start of buffer. | ||
| 147 | ((bobp) | ||
| 148 | (setq not-indented nil))))))) | ||
| 149 | |||
| 150 | ;; We've figured out the indentation, so do it. | ||
| 151 | (if (and cur-indent (> cur-indent 0)) | ||
| 152 | (indent-line-to cur-indent) | ||
| 153 | (indent-line-to 0))))) | ||
| 154 | |||
| 155 | |||
| 156 | (defvar nginx-mode-map | ||
| 157 | (let | ||
| 158 | ((map (make-sparse-keymap))) | ||
| 159 | (define-key map "\C-j" 'newline-and-indent) | ||
| 160 | (define-key map "\C-m" 'newline-and-indent) | ||
| 161 | map) | ||
| 162 | "Keymap for editing nginx config files.") | ||
| 163 | |||
| 164 | ;;;###autoload | ||
| 165 | (define-derived-mode nginx-mode prog-mode "Nginx" | ||
| 166 | "Major mode for highlighting nginx config files. | ||
| 167 | |||
| 168 | The variable nginx-indent-level controls the amount of indentation. | ||
| 169 | \\{nginx-mode-map}" | ||
| 170 | :syntax-table nginx-mode-syntax-table | ||
| 171 | |||
| 172 | (use-local-map nginx-mode-map) | ||
| 173 | |||
| 174 | (set (make-local-variable 'comment-start) "# ") | ||
| 175 | (set (make-local-variable 'comment-start-skip) "#+ *") | ||
| 176 | (set (make-local-variable 'comment-end) "") | ||
| 177 | (set (make-local-variable 'comment-auto-fill-only-comments) t) | ||
| 178 | |||
| 179 | (set (make-local-variable 'indent-line-function) 'nginx-indent-line) | ||
| 180 | (set (make-local-variable 'indent-tabs-mode) nginx-indent-tabs-mode) | ||
| 181 | (set (make-local-variable 'require-final-newline) t) | ||
| 182 | (set (make-local-variable 'paragraph-ignore-fill-prefix) t) | ||
| 183 | (set (make-local-variable 'paragraph-start) "\f\\|[ ]*$\\|#$") | ||
| 184 | (set (make-local-variable 'paragraph-separate) "\\([ \f]*\\|#\\)$") | ||
| 185 | |||
| 186 | (set (make-local-variable 'font-lock-defaults) | ||
| 187 | '(nginx-font-lock-keywords nil))) | ||
| 188 | |||
| 189 | ;;;###autoload | ||
| 190 | (add-to-list 'auto-mode-alist '("nginx\\.conf\\'" . nginx-mode)) | ||
| 191 | ;;;###autoload | ||
| 192 | (add-to-list 'auto-mode-alist '("/nginx/.+\\.conf\\'" . nginx-mode)) | ||
| 193 | ;;;###autoload | ||
| 194 | (add-to-list | ||
| 195 | 'magic-fallback-mode-alist | ||
| 196 | '("\\(?:.*\n\\)*\\(?:http\\|server\\|location .+\\|upstream .+\\)[ \n\t]+{" | ||
| 197 | . nginx-mode)) | ||
| 198 | |||
| 199 | (provide 'nginx-mode) | ||
| 200 | |||
| 201 | ;;; nginx-mode.el ends here | ||
