Showing
14 changed files
with
967 additions
and
30 deletions
auto-save-list/.saves-11439-oyster~
deleted
100644 → 0
File mode changed
config/bison-mode.el
0 → 100644
config/index.el
deleted
100644 → 0
1 | -(require 'package) | ||
2 | -(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")) | ||
3 | -(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/")) | ||
4 | -(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) | ||
5 | -(package-initialize) | ||
6 | - | ||
7 | -(unless (package-installed-p 'use-package) | ||
8 | - (package-refresh-contents) | ||
9 | - (package-install 'use-package)) | ||
10 | - | ||
11 | -(require 'use-package) | ||
12 | -(setq use-package-always-ensure t) | ||
13 | - | ||
14 | -(defun activate (&rest modes) | ||
15 | - (mapc (lambda (mode) | ||
16 | - (load (concat "~/.emacs.d/config/" (symbol-name mode)))) | ||
17 | - modes)) | ||
18 | - |
1 | (use-package rainbow-delimiters | 1 | (use-package rainbow-delimiters |
2 | - :init | 2 | + :config |
3 | (add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode) | 3 | (add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode) |
4 | (add-hook 'lisp-mode-hook 'rainbow-delimiters-mode)) | 4 | (add-hook 'lisp-mode-hook 'rainbow-delimiters-mode)) |
5 | 5 | ||
6 | 6 | ||
7 | (use-package paredit | 7 | (use-package paredit |
8 | - :init | 8 | + :config |
9 | (add-hook 'emacs-lisp-mode-hook 'paredit-mode) | 9 | (add-hook 'emacs-lisp-mode-hook 'paredit-mode) |
10 | (add-hook 'lisp-mode-hook 'paredit-mode)) | 10 | (add-hook 'lisp-mode-hook 'paredit-mode)) | ... | ... |
... | @@ -46,7 +46,7 @@ | ... | @@ -46,7 +46,7 @@ |
46 | ((:url . "https://github.com/Malabarba/aggressive-indent-mode") | 46 | ((:url . "https://github.com/Malabarba/aggressive-indent-mode") |
47 | (:keywords "indent" "lisp" "maint" "tools"))]) | 47 | (:keywords "indent" "lisp" "maint" "tools"))]) |
48 | (ahungry-theme . | 48 | (ahungry-theme . |
49 | - [(1 4 0) | 49 | + [(1 5 0) |
50 | ((emacs | 50 | ((emacs |
51 | (24))) | 51 | (24))) |
52 | "Ahungry color theme for Emacs. Make sure to (load-theme 'ahungry)." tar | 52 | "Ahungry color theme for Emacs. Make sure to (load-theme 'ahungry)." tar |
... | @@ -335,7 +335,7 @@ | ... | @@ -335,7 +335,7 @@ |
335 | ((:keywords "killing" "convenience") | 335 | ((:keywords "killing" "convenience") |
336 | (:url . "https://github.com/leoliu/easy-kill"))]) | 336 | (:url . "https://github.com/leoliu/easy-kill"))]) |
337 | (ebdb . | 337 | (ebdb . |
338 | - [(0 3 2) | 338 | + [(0 3 3) |
339 | ((emacs | 339 | ((emacs |
340 | (25 1)) | 340 | (25 1)) |
341 | (cl-lib | 341 | (cl-lib |
... | @@ -355,7 +355,7 @@ | ... | @@ -355,7 +355,7 @@ |
355 | ((:url . "http://elpa.gnu.org/packages/ebdb-gnorb.html") | 355 | ((:url . "http://elpa.gnu.org/packages/ebdb-gnorb.html") |
356 | (:keywords))]) | 356 | (:keywords))]) |
357 | (ebdb-i18n-chn . | 357 | (ebdb-i18n-chn . |
358 | - [(1 1) | 358 | + [(1 2) |
359 | ((pyim | 359 | ((pyim |
360 | (1 6 0)) | 360 | (1 6 0)) |
361 | (ebdb | 361 | (ebdb |
... | @@ -763,7 +763,7 @@ | ... | @@ -763,7 +763,7 @@ |
763 | ((:url . "https://github.com/michael-heerdegen/on-screen.el") | 763 | ((:url . "https://github.com/michael-heerdegen/on-screen.el") |
764 | (:keywords "convenience"))]) | 764 | (:keywords "convenience"))]) |
765 | (org . | 765 | (org . |
766 | - [(20170918) | 766 | + [(20170925) |
767 | nil "Outline-based notes management and organizer" tar nil]) | 767 | nil "Outline-based notes management and organizer" tar nil]) |
768 | (org-edna . | 768 | (org-edna . |
769 | [(1 0 -3 1) | 769 | [(1 0 -3 1) |
... | @@ -1018,7 +1018,7 @@ | ... | @@ -1018,7 +1018,7 @@ |
1018 | ((:keywords "convenience") | 1018 | ((:keywords "convenience") |
1019 | (:url . "https://github.com/abo-abo/tiny"))]) | 1019 | (:url . "https://github.com/abo-abo/tiny"))]) |
1020 | (tramp-theme . | 1020 | (tramp-theme . |
1021 | - [(0 1 1) | 1021 | + [(0 2) |
1022 | ((emacs | 1022 | ((emacs |
1023 | (24 1))) | 1023 | (24 1))) |
1024 | "Custom theme for remote buffers" single | 1024 | "Custom theme for remote buffers" single | ... | ... |
1 | -Good signature from 474F05837FBDEF9B GNU ELPA Signing Agent <elpasign@elpa.gnu.org> (trust undefined) created at 2017-09-18T18:10:02+0900 using DSA | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +Good signature from 474F05837FBDEF9B GNU ELPA Signing Agent <elpasign@elpa.gnu.org> (trust undefined) created at 2017-09-30T06:10:02+0900 using DSA | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | (1 | 1 | (1 |
2 | + (zone-quotes . | ||
3 | + [(20170919 1825) | ||
4 | + ((emacs | ||
5 | + (24)) | ||
6 | + (cl-lib | ||
7 | + (0 5))) | ||
8 | + "A zone program to display quotes from a specific collection" single]) | ||
2 | (zone-nyan . | 9 | (zone-nyan . |
3 | [(0 2 2) | 10 | [(0 2 2) |
4 | ((esxml | 11 | ((esxml |
... | @@ -460,7 +467,7 @@ | ... | @@ -460,7 +467,7 @@ |
460 | [(12) | 467 | [(12) |
461 | nil "A theme loosely based on Tron: Legacy colors" single]) | 468 | nil "A theme loosely based on Tron: Legacy colors" single]) |
462 | (transmission . | 469 | (transmission . |
463 | - [(0 11 1) | 470 | + [(0 12) |
464 | ((emacs | 471 | ((emacs |
465 | (24 4)) | 472 | (24 4)) |
466 | (let-alist | 473 | (let-alist |
... | @@ -575,7 +582,7 @@ | ... | @@ -575,7 +582,7 @@ |
575 | [(0 2) | 582 | [(0 2) |
576 | nil "A mode for SystemTap" single]) | 583 | nil "A mode for SystemTap" single]) |
577 | (systemd . | 584 | (systemd . |
578 | - [(1 4 1) | 585 | + [(1 6) |
579 | nil "Major mode for editing systemd units" tar]) | 586 | nil "Major mode for editing systemd units" tar]) |
580 | (syslog-mode . | 587 | (syslog-mode . |
581 | [(2 2) | 588 | [(2 2) |
... | @@ -3789,7 +3796,7 @@ | ... | @@ -3789,7 +3796,7 @@ |
3789 | [(0 2 2) | 3796 | [(0 2 2) |
3790 | nil "Aspell extra dictionary for Drupal" tar]) | 3797 | nil "Aspell extra dictionary for Drupal" tar]) |
3791 | (drupal-mode . | 3798 | (drupal-mode . |
3792 | - [(0 7 1) | 3799 | + [(0 7 3) |
3793 | ((php-mode | 3800 | ((php-mode |
3794 | (1 5 0))) | 3801 | (1 5 0))) |
3795 | "Advanced minor mode for Drupal development" tar]) | 3802 | "Advanced minor mode for Drupal development" tar]) | ... | ... |
This diff could not be displayed because it is too large.
1 | +;;; bison-mode-autoloads.el --- automatically extracted autoloads | ||
2 | +;; | ||
3 | +;;; Code: | ||
4 | +(add-to-list 'load-path (or (file-name-directory #$) (car load-path))) | ||
5 | + | ||
6 | +;;;### (autoloads nil "bison-mode" "bison-mode.el" (22991 12177 223473 | ||
7 | +;;;;;; 427000)) | ||
8 | +;;; Generated autoloads from bison-mode.el | ||
9 | + | ||
10 | +(add-to-list 'auto-mode-alist '("\\.y\\'" . bison-mode)) | ||
11 | + | ||
12 | +(add-to-list 'auto-mode-alist '("\\.l\\'" . bison-mode)) | ||
13 | + | ||
14 | +(add-to-list 'auto-mode-alist '("\\.jison\\'" . jison-mode)) | ||
15 | + | ||
16 | +(autoload 'bison-mode "bison-mode" "\ | ||
17 | +Major mode for editing bison/yacc files. | ||
18 | + | ||
19 | +\(fn)" t nil) | ||
20 | + | ||
21 | +(autoload 'jison-mode "bison-mode" "\ | ||
22 | + | ||
23 | + | ||
24 | +\(fn)" t nil) | ||
25 | + | ||
26 | +;;;*** | ||
27 | + | ||
28 | +;; Local Variables: | ||
29 | +;; version-control: never | ||
30 | +;; no-byte-compile: t | ||
31 | +;; no-update-autoloads: t | ||
32 | +;; End: | ||
33 | +;;; bison-mode-autoloads.el ends here |
1 | +(define-package "bison-mode" "20160616.2252" "Major mode for editing bison, yacc and lex files." 'nil :commit "314af3b7af7eb897fd3932616cb8600a85228cea" :keywords '("bison-mode" "yacc-mode")) |
No preview for this file type
elpa/bison-mode-20160616.2252/bison-mode.el
0 → 100644
1 | +;;; bison-mode.el --- Major mode for editing bison, yacc and lex files. | ||
2 | + | ||
3 | +;; Copyright (C) 1998 Eric Beuscher | ||
4 | +;; | ||
5 | +;; Author: Eric Beuscher <beuscher@eecs.tulane.edu> | ||
6 | +;; Created: 2 Feb 1998 | ||
7 | +;; Version: 0.2 | ||
8 | +;; Package-Version: 20160616.2252 | ||
9 | +;; Keywords: bison-mode, yacc-mode | ||
10 | + | ||
11 | +;; This program is free software; you can redistribute it and/or modify | ||
12 | +;; it under the terms of the GNU General Public License as published by | ||
13 | +;; the Free Software Foundation; either version 2 of the License, or | ||
14 | +;; (at your option) any later version. | ||
15 | + | ||
16 | +;; This program is distributed in the hope that it will be useful, | ||
17 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | +;; GNU General Public License for more details. | ||
20 | + | ||
21 | +;;; Commentary: | ||
22 | + | ||
23 | +;;;; I wrote this since I saw one mode for yacc files out there roaming the | ||
24 | +;;;; world. I was daunted by the fact the it was written in 1990, and Emacs | ||
25 | +;;;; has evolved so much since then (this I assume based on its evolution since | ||
26 | +;;;; i started using it). So I figured if i wanted one, I should make it | ||
27 | +;;;; myself. Please excuse idiosyncrasies, as this was my first major mode | ||
28 | +;;;; of this kind. The indentation code may be a bit weird, I am not sure, | ||
29 | +;;;; it was my first go at doing Emacs indentation, so I look at how other | ||
30 | +;;;; modes did it, but then basically did what I thought was right | ||
31 | + | ||
32 | +;;;; I hope this is useful to other hackers, and happy Bison/Yacc hacking | ||
33 | +;;;; If you have ideas/suggestions/problems with this code, I can be reached at | ||
34 | +;;;; beuscher@eecs.tulane.edu | ||
35 | + | ||
36 | +;;;; Eric --- Sat Mar 7 1:40:20 CDT 1998 | ||
37 | + | ||
38 | +;;;; Bison Sections: | ||
39 | +;;;; there are five sections to a bison file (if you include the area above the | ||
40 | +;;;; C declarations section. most everything in this file either does | ||
41 | +;;;; actions based on which section you are deemed to be in, or based on an | ||
42 | +;;;; assumption that the function will only be called from certain sections. | ||
43 | +;;;; the function `bison--section-p' is the section parser | ||
44 | + | ||
45 | +;;;; Indentation: | ||
46 | +;;;; indentations are done based on the section of code you are in. there is | ||
47 | +;;;; a procedure `bison--within-braced-c-expression-p' that checks for being in | ||
48 | +;;;; C code. if you are within c-code, indentations should occur based on | ||
49 | +;;;; how you have your C indentation set up. i am pretty sure this is the | ||
50 | +;;;; case. | ||
51 | +;;;; there are four variables, which control bison indentation within either | ||
52 | +;;;; the bison declarations section or the bison grammar section | ||
53 | +;;;; `bison-rule-separator-column' | ||
54 | +;;;; `bison-rule-separator-column' | ||
55 | +;;;; `bison-decl-type-column' | ||
56 | +;;;; `bison-decl-token-column' | ||
57 | + | ||
58 | +;;;; flaw: indentation works on a per-line basis, unless within braced C sexp, | ||
59 | +;;;; i should fix this someday | ||
60 | +;;;; and to make matters worse, i never took out c-indent-region, so that is | ||
61 | +;;;; still the state of the `indent-region-function' variable | ||
62 | + | ||
63 | +;;;; Electricity: | ||
64 | +;;;; by default, there are electric -colon, -pipe, -open-brace, -close-brace, | ||
65 | +;;;; -semicolon, -percent, -less-than, -greater-than | ||
66 | +;;;; the indentation caused by these work closely with the 4 indentation | ||
67 | +;;;; variables mentioned above. | ||
68 | +;;;; any of these can be turned off individually by setting the appropriate | ||
69 | +;;;; `bison-electric-...' variable. or all of them can be turned off by | ||
70 | +;;;; setting `bison-all-electricity-off' | ||
71 | + | ||
72 | +;;;; todo: should make available a way to use C-electricity if in C sexps | ||
73 | + | ||
74 | +;;; Code: | ||
75 | + | ||
76 | +(require 'cc-mode) | ||
77 | + | ||
78 | +;;;###autoload | ||
79 | +(add-to-list 'auto-mode-alist '("\\.y\\'" . bison-mode)) | ||
80 | +;;;###autoload | ||
81 | +(add-to-list 'auto-mode-alist '("\\.l\\'" . bison-mode)) | ||
82 | +;;;###autoload | ||
83 | +(add-to-list 'auto-mode-alist '("\\.jison\\'" . jison-mode)) | ||
84 | + | ||
85 | +;; *************** internal vars *************** | ||
86 | + | ||
87 | +(defvar bison--declarers '("%union" "%token" "%type" | ||
88 | + "%left" "%right" "%nonassoc") | ||
89 | + "commands which can declare a token or state type") | ||
90 | + | ||
91 | +(defvar bison--word-constituent-re "\\(\\sw\\|_\\)") | ||
92 | +(defvar bison--production-re | ||
93 | + (concat "^" bison--word-constituent-re "+:")) | ||
94 | + | ||
95 | +(defvar bison--pre-c-decls-section 0 | ||
96 | + "section before c-declarations-section, if that section exists") | ||
97 | +(defvar bison--c-decls-section 1 | ||
98 | + "section denoted by %{ and $} for c-declarations at the top of a bison file") | ||
99 | +(defvar bison--bison-decls-section 2 | ||
100 | + "section before the rules section") | ||
101 | +(defvar bison--grammar-rules-section 3 | ||
102 | + "section delimited by %%'s where productions and rules are enumerated") | ||
103 | +(defvar bison--c-code-section 4 | ||
104 | + "section after the second %% where c-code can be placed") | ||
105 | + | ||
106 | +(defvar bison--c-decls-section-opener "%{") | ||
107 | +(defvar bison--c-decls-section-closer "%}") | ||
108 | +(defvar bison--grammar-rules-section-delimeter "%%") | ||
109 | + | ||
110 | + | ||
111 | +;; *************** user-definable vars *************** | ||
112 | + | ||
113 | +(defvar bison-rule-separator-column 8 | ||
114 | + "column for rule and production separators \"|\" and \";\"") | ||
115 | +(defvar bison-rule-enumeration-column 16 | ||
116 | + "column for beginning enumeration of a production's rules") | ||
117 | +(defvar bison-decl-type-column 8 | ||
118 | + "columnn in which tokens' and states' types should be when declared") | ||
119 | +(defvar bison-decl-token-column 24 | ||
120 | + "column in which tokens and states are listed when declared, | ||
121 | +as with %token, %type, ...") | ||
122 | + | ||
123 | + | ||
124 | +(defvar bison-all-electricity-off nil | ||
125 | + "non-nil means all electric keys will be disabled, | ||
126 | +nil means that a bison-electric-* key will be on or off based on the individual | ||
127 | +key's electric variable") | ||
128 | + | ||
129 | +;;; i know lisp has the dual name spaces, but i find it more aesthetically | ||
130 | +;;; pleasing to not take advantage of that | ||
131 | +(defvar bison-electric-colon-v t | ||
132 | + "non-nil means use an electric colon") | ||
133 | +(defvar bison-electric-pipe-v t | ||
134 | + "non-nil means use an electric pipe") | ||
135 | +(defvar bison-electric-open-brace-v t | ||
136 | + "non-nil means use an electric open-brace") | ||
137 | +(defvar bison-electric-close-brace-v t | ||
138 | + "non-nil means use an electric close-brace") | ||
139 | +(defvar bison-electric-semicolon-v t | ||
140 | + "non-nil means use an electric semicolon") | ||
141 | +(defvar bison-electric-percent-v t | ||
142 | + "non-nil means use an electric percent") | ||
143 | +(defvar bison-electric-less-than-v t | ||
144 | + "non-nil means use an electric less-than") | ||
145 | +(defvar bison-electric-greater-than-v t | ||
146 | + "non-nil means use an electric greater-than") | ||
147 | + | ||
148 | + | ||
149 | +(defconst bison-font-lock-keywords | ||
150 | + (append | ||
151 | + (list | ||
152 | + (cons (concat "^\\(" (regexp-opt bison--declarers) "\\)") | ||
153 | + '(1 font-lock-keyword-face)) | ||
154 | + ) | ||
155 | + c-font-lock-keywords) | ||
156 | + "Default expressions to highlight in Bison mode") | ||
157 | + | ||
158 | +;; *************** utilities *************** | ||
159 | + | ||
160 | +(defun just-no-space () | ||
161 | + "Delete all spaces and tabs around point, leaving no spaces." | ||
162 | + (interactive "*") | ||
163 | + (skip-chars-backward " \t") | ||
164 | + (delete-region (point) (progn (skip-chars-forward " \t") (point))) | ||
165 | + t) | ||
166 | + | ||
167 | +(defun previous-white-space-p () | ||
168 | + "return t if there is whitespace between the beginning of the line and the | ||
169 | +current (point)" | ||
170 | + (save-excursion | ||
171 | + (let ((current-point (point))) | ||
172 | + (beginning-of-line) | ||
173 | + (if (re-search-forward "\\s " current-point t) | ||
174 | + t | ||
175 | + nil)))) | ||
176 | + | ||
177 | +(defun previous-non-ws-p () | ||
178 | + "return t if there are non-whitespace characters between beginning of line | ||
179 | +and \(point\)" | ||
180 | + (save-excursion | ||
181 | + (let ((current-point (point))) | ||
182 | + (beginning-of-line) | ||
183 | + (re-search-forward "[^ \t]" current-point t) | ||
184 | + ))) | ||
185 | + | ||
186 | +(defun following-non-ws-p () | ||
187 | + "return t if there are non-whitespace characters on the line" | ||
188 | + (save-excursion | ||
189 | + (let ((current-point (point))) | ||
190 | + (end-of-line) | ||
191 | + (re-search-backward "[^ \t]+" current-point t) | ||
192 | + ))) | ||
193 | + | ||
194 | +(defun line-of-whitespace-p () | ||
195 | + "return t if the line consists of nothiing but whitespace, nil otherwise" | ||
196 | + (save-excursion | ||
197 | + (let ((eol (progn (end-of-line) (point)))) | ||
198 | + (beginning-of-line) ;; should already be there anyway | ||
199 | + (not (re-search-forward "[^ \t\n]" eol t))))) | ||
200 | + | ||
201 | +;; *************** bison-mode *************** | ||
202 | + | ||
203 | +;;;###autoload | ||
204 | +(define-derived-mode bison-mode c-mode "Bison" | ||
205 | + "Major mode for editing bison/yacc files." | ||
206 | + | ||
207 | + ;; try to set the indentation correctly | ||
208 | + (setq c-basic-offset 4) | ||
209 | + | ||
210 | + (c-set-offset 'knr-argdecl-intro 0) | ||
211 | + | ||
212 | + ;; remove auto and hungry anything | ||
213 | + (c-toggle-auto-hungry-state -1) | ||
214 | + (c-toggle-auto-newline -1) | ||
215 | + (c-toggle-hungry-state -1) | ||
216 | + | ||
217 | + (use-local-map bison-mode-map) | ||
218 | + | ||
219 | + (define-key bison-mode-map ":" 'bison-electric-colon) | ||
220 | + (define-key bison-mode-map "|" 'bison-electric-pipe) | ||
221 | + (define-key bison-mode-map "{" 'bison-electric-open-brace) | ||
222 | + (define-key bison-mode-map "}" 'bison-electric-close-brace) | ||
223 | + (define-key bison-mode-map ";" 'bison-electric-semicolon) | ||
224 | + (define-key bison-mode-map "%" 'bison-electric-percent) | ||
225 | + (define-key bison-mode-map "<" 'bison-electric-less-than) | ||
226 | + (define-key bison-mode-map ">" 'bison-electric-greater-than) | ||
227 | + | ||
228 | + (define-key bison-mode-map [tab] 'bison-indent-line) | ||
229 | + | ||
230 | + (make-local-variable 'indent-line-function) | ||
231 | + (setq indent-line-function 'bison-indent-new-line) | ||
232 | + (make-local-variable 'comment-start) | ||
233 | + (make-local-variable 'comment-end) | ||
234 | + (setq comment-start "/*" | ||
235 | + comment-end "*/") | ||
236 | + (make-local-variable 'font-lock-keywords) | ||
237 | + (setq font-lock-keywords nil) | ||
238 | + (set (make-local-variable 'font-lock-defaults) '(bison-font-lock-keywords))) | ||
239 | + | ||
240 | + | ||
241 | +;; *************** section parsers *************** | ||
242 | + | ||
243 | +(defun bison--section-p () | ||
244 | + "Return the section that user is currently in" | ||
245 | + (save-excursion | ||
246 | + (let ((bound (point))) | ||
247 | + (goto-char (point-min)) | ||
248 | + (bison--section-p-helper bound)))) | ||
249 | + | ||
250 | +(defun bison--section-p-helper (bound) | ||
251 | + (if (re-search-forward | ||
252 | + (concat "^" bison--c-decls-section-opener) | ||
253 | + bound t) | ||
254 | + (if (re-search-forward | ||
255 | + (concat "^" bison--c-decls-section-closer) | ||
256 | + bound t) | ||
257 | + (if (re-search-forward | ||
258 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
259 | + bound t) | ||
260 | + (if (re-search-forward | ||
261 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
262 | + bound t) | ||
263 | + bison--c-code-section | ||
264 | + bison--grammar-rules-section) | ||
265 | + bison--bison-decls-section) | ||
266 | + bison--c-decls-section) | ||
267 | + (if (re-search-forward | ||
268 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
269 | + bound t) | ||
270 | + (if (re-search-forward | ||
271 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
272 | + bound t) | ||
273 | + bison--c-code-section | ||
274 | + bison--grammar-rules-section) | ||
275 | + (if (re-search-forward | ||
276 | + (concat "^" bison--c-decls-section-opener) | ||
277 | + nil t) | ||
278 | + bison--pre-c-decls-section | ||
279 | + (if (re-search-forward | ||
280 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
281 | + nil t) | ||
282 | + bison--bison-decls-section | ||
283 | + bison--pre-c-decls-section))))) | ||
284 | + | ||
285 | + | ||
286 | +;; *************** syntax parsers *************** | ||
287 | + | ||
288 | +(defun bison--production-p () | ||
289 | + "return t if the \(point\) rests immediately after a production" | ||
290 | + (save-excursion | ||
291 | + (let ((current-point (point))) | ||
292 | + (beginning-of-line) | ||
293 | + (let ((position (re-search-forward | ||
294 | + bison--production-re current-point t))) | ||
295 | + (and position | ||
296 | + (not (previous-white-space-p)) | ||
297 | + (= position current-point)))))) | ||
298 | + | ||
299 | +(defun bison--find-production-opener () | ||
300 | + "return and goto the point of the nearest production opener above \(point\)" | ||
301 | + (re-search-backward bison--production-re nil t)) | ||
302 | + | ||
303 | + | ||
304 | +(defun bison--find-next-production () | ||
305 | + "return the position of the beginning of the next production, | ||
306 | +or nil if there isnt one" | ||
307 | + (save-excursion | ||
308 | + (if (re-search-forward bison--production-re nil t) | ||
309 | + (progn | ||
310 | + (beginning-of-line) | ||
311 | + (point)) | ||
312 | + nil))) | ||
313 | + | ||
314 | +(defun bison--find-grammar-end () | ||
315 | + "return the position of the end of the grammar rules (assuming we are within | ||
316 | +the grammar rules section), or nil if there isnt one" | ||
317 | + (save-excursion | ||
318 | + (if (re-search-forward | ||
319 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
320 | + nil t) | ||
321 | + (progn | ||
322 | + (beginning-of-line) | ||
323 | + (point)) | ||
324 | + nil))) | ||
325 | + | ||
326 | +(defun bison--find-grammar-begin () | ||
327 | + "return the position of the beginning of the grammar rules (assuming we are | ||
328 | +within the grammar rules section), or nil if there isnt one" | ||
329 | + (save-excursion | ||
330 | + (if (re-search-backward | ||
331 | + (concat "^" bison--grammar-rules-section-delimeter) | ||
332 | + nil t) | ||
333 | + (point) | ||
334 | + nil))) | ||
335 | + | ||
336 | +(defun bison--within-started-production-p () | ||
337 | + "is used by bison-electric-* functions to determine actions | ||
338 | +return t if within a production, nil if not | ||
339 | + | ||
340 | +a point is within a production if there is some non whitespace text before | ||
341 | +either the beginnings of another production or the end of the grammar rules" | ||
342 | + (save-excursion | ||
343 | + (let ((bound (cond ((bison--find-next-production)) | ||
344 | + ((bison--find-grammar-end)) | ||
345 | + (t nil)))) | ||
346 | + (if bound | ||
347 | + (let ((sval (re-search-forward | ||
348 | + (concat "\\(\\s \\|" ;; whitespace or | ||
349 | + ;; comments | ||
350 | + (regexp-quote comment-start) | ||
351 | + "\\(.\\|\n\\)*" ;; comment body | ||
352 | + (regexp-quote comment-end) | ||
353 | + "\\)+") ;; end or | ||
354 | + bound t))) | ||
355 | + (if sval | ||
356 | + (not (= sval bound)) | ||
357 | + nil)) | ||
358 | + nil)))) | ||
359 | + | ||
360 | +(defun bison--within-some-sexp-p (starter ender) | ||
361 | + "return t if the \(point\) is within the sexp marked by the re's STARTER and | ||
362 | +ENDER" | ||
363 | + (save-excursion | ||
364 | + (let ((current-point (point))) | ||
365 | + (if (re-search-backward starter nil t) ;; find nearest starter | ||
366 | + ;; look for ender, if found, then not within sexp | ||
367 | + (progn | ||
368 | + (goto-char (match-end 0)) | ||
369 | + (not (re-search-forward ender current-point t))))))) | ||
370 | + | ||
371 | +(defun bison--within-c-comment-p () | ||
372 | + "return t if the point is within a c comment delimited by \"/*\" \"*/\"" | ||
373 | + (bison--within-some-sexp-p (regexp-quote comment-start) | ||
374 | + (regexp-quote comment-end))) | ||
375 | + | ||
376 | + | ||
377 | +(defun bison--within-string-p (&optional point) | ||
378 | + " | ||
379 | +start from the beginning of the buffer and toggle state as un-escaped \"'s are | ||
380 | +found." | ||
381 | + (let ((point (or point (point))) | ||
382 | + (in-p nil)) | ||
383 | + (save-excursion | ||
384 | + (goto-char (point-min)) | ||
385 | + | ||
386 | + (while (re-search-forward "[^\\]\"" point t) | ||
387 | + (setq in-p (not in-p))) | ||
388 | + | ||
389 | + in-p))) | ||
390 | + | ||
391 | +;;; bison--within-braced-c-expression-p | ||
392 | +;;; new and improved, no more recursion, does not break when literal strings | ||
393 | +;;; contain un-matched braces | ||
394 | +(defun bison--within-braced-c-expression-p (section) | ||
395 | + "return t if the point is within an sexp delimited by braces \({,}\) | ||
396 | +" | ||
397 | + (save-excursion | ||
398 | + (bison--within-braced-c-expression-p-h section (point)))) | ||
399 | + | ||
400 | +(defun bison--within-braced-c-expression-p-h (section low-pt) | ||
401 | + " | ||
402 | +Notes: | ||
403 | +save excursion is done higher up, so i dont concern myself here. | ||
404 | +" | ||
405 | + (cond ((= section bison--pre-c-decls-section) nil) | ||
406 | + ((= section bison--c-decls-section) | ||
407 | + (let ((opener (save-excursion (search-backward "%{")))) | ||
408 | + (bison--within-braced-c-expression-p-h-h opener low-pt))) | ||
409 | + ((= section bison--bison-decls-section) | ||
410 | + (let ((opener (save-excursion | ||
411 | + (or (search-backward "%}" nil t) | ||
412 | + (point-min))))) | ||
413 | + (bison--within-braced-c-expression-p-h-h opener low-pt))) | ||
414 | + ((= section bison--grammar-rules-section) | ||
415 | + (let ((opener (save-excursion (bison--find-production-opener)))) | ||
416 | + (if opener | ||
417 | + (bison--within-braced-c-expression-p-h-h opener low-pt) | ||
418 | + nil))) | ||
419 | + ((= section bison--c-code-section) | ||
420 | + t))) | ||
421 | + | ||
422 | +(defun bison--within-braced-c-expression-p-h-h (high-pt low-pt) | ||
423 | + " | ||
424 | +Notes: | ||
425 | +HIGH-PT goes toward (point-min), LOW-PT goes toward (point-max) | ||
426 | +save excursion is done higher up, so i dont concern myself here. | ||
427 | +" | ||
428 | + (let ((pt (point))) | ||
429 | + (let ((success nil) (count 1) (done nil)) | ||
430 | + ;; loop until open brace found, that is not in comment or string literal | ||
431 | + (while (and (not done) | ||
432 | + (re-search-backward "[^%]{" high-pt t count)) ;find nearest | ||
433 | + ;starter | ||
434 | + (goto-char (match-end 0)) | ||
435 | + (if (or (bison--within-c-comment-p) | ||
436 | + (bison--within-string-p)) | ||
437 | + | ||
438 | + (setq count (+ count 1)) | ||
439 | + (progn | ||
440 | + (setq success t) | ||
441 | + (setq done t)))) | ||
442 | + | ||
443 | + (if success | ||
444 | + (let ((end-pt | ||
445 | + (condition-case nil | ||
446 | + (progn | ||
447 | + (backward-char) | ||
448 | + (forward-sexp) | ||
449 | + (point)) | ||
450 | + (error nil)))) | ||
451 | + (if end-pt | ||
452 | + (if (> end-pt low-pt) | ||
453 | + t ; then in braced-c-exp | ||
454 | + nil) | ||
455 | + t)) ; if no sexp close brace, then w/in | ||
456 | + nil)))) | ||
457 | + | ||
458 | + | ||
459 | +(defun bison--bison-decl-opener-p (bol eol) | ||
460 | + "return t if the current line is a bison declaration starter | ||
461 | +\(i.e. has a %type, %token, %right, ...\)" | ||
462 | + (save-excursion | ||
463 | + (goto-char bol) | ||
464 | + (re-search-forward | ||
465 | + (concat "^" (regexp-opt (copy-sequence bison--declarers))) eol t))) | ||
466 | + | ||
467 | +(defun bison--production-opener-p (bol eol) | ||
468 | + "return t if the current line is a line that introduces a new production" | ||
469 | + (save-excursion | ||
470 | + (goto-char bol) | ||
471 | + (re-search-forward bison--production-re eol t))) | ||
472 | + | ||
473 | +(defun bison--find-bison-semicolon () | ||
474 | + "return the position of next semicolon not within braces, nil otherwise" | ||
475 | + (save-excursion | ||
476 | + (if (search-forward ";" nil t) | ||
477 | + (if (not (bison--within-braced-c-expression-p (bison--section-p))) | ||
478 | + (point) | ||
479 | + (bison--find-bison-semicolon)) | ||
480 | + nil))) | ||
481 | + | ||
482 | +(defun bison--within-production-body-p (section) | ||
483 | + "return t if the \(point\) is within the body of a production | ||
484 | + | ||
485 | +this procedure will fail if it is in a production header" | ||
486 | + (save-excursion | ||
487 | + (if (= section bison--grammar-rules-section) | ||
488 | + (let ((current-point (point))) | ||
489 | + (if (re-search-backward bison--production-re nil t) | ||
490 | + t | ||
491 | + nil)) | ||
492 | + nil))) | ||
493 | + | ||
494 | +(defun bison--production-alternative-p (bol eol section) | ||
495 | + "return t if the current line contains a \"|\" used to designate a rule | ||
496 | +alternative" | ||
497 | + (save-excursion | ||
498 | + (goto-char bol) | ||
499 | + (if (search-forward "|" eol t) | ||
500 | + (not (bison--within-braced-c-expression-p section)) | ||
501 | + nil))) | ||
502 | + | ||
503 | + | ||
504 | +;; *************** indent functions *************** | ||
505 | + | ||
506 | +(defun bison--handle-indent-c-sexp (section indent-column bol) | ||
507 | + (let* ((o-brace (re-search-backward "[^%]{" bol t)) | ||
508 | + ) | ||
509 | + (if o-brace | ||
510 | + (if (save-excursion | ||
511 | + (goto-char o-brace) | ||
512 | + (bison--within-braced-c-expression-p section)) | ||
513 | + (c-indent-line) | ||
514 | + (if (= (current-indentation) o-brace) ;; if o-brace is first char | ||
515 | + (if (not (= o-brace indent-column)) ;; but not in right spot | ||
516 | + (progn | ||
517 | + (back-to-indentation) | ||
518 | + (just-no-space) | ||
519 | + (indent-to-column indent-column)) | ||
520 | + ;; else all is good | ||
521 | + ) | ||
522 | + ;; else, non-ws before o-brace, leave it alone | ||
523 | + )) | ||
524 | + (c-indent-line)))) | ||
525 | + | ||
526 | +(defun bison-indent-new-line (&optional c-sexp) | ||
527 | + "Indent a fresh line of bison code | ||
528 | + | ||
529 | +assumes indenting a new line, i.e. at column 0 | ||
530 | +" | ||
531 | + (interactive) | ||
532 | + | ||
533 | + (let* ((section (bison--section-p)) | ||
534 | + (c-sexp (or c-sexp (bison--within-braced-c-expression-p section))) | ||
535 | + ) | ||
536 | + (cond | ||
537 | + (c-sexp | ||
538 | + (cond | ||
539 | + ((= section bison--grammar-rules-section) | ||
540 | + (c-indent-line | ||
541 | + (save-excursion | ||
542 | + (forward-line -1) | ||
543 | + (let ((bol (save-excursion (beginning-of-line) (point))) | ||
544 | + (eol (save-excursion (end-of-line) (point)))) | ||
545 | + (if (bison--production-opener-p bol eol) | ||
546 | + (list | ||
547 | + (cons 'defun-block-intro | ||
548 | + (progn | ||
549 | + (re-search-forward bison--production-re) ; SIGERR | ||
550 | + (- (re-search-forward "[^ \t]") ; SIGERR | ||
551 | + 1)))) | ||
552 | + nil))))) | ||
553 | + (t (c-indent-line)))) | ||
554 | + ((= section bison--pre-c-decls-section) | ||
555 | + (c-indent-line)) | ||
556 | + ((= section bison--bison-decls-section) | ||
557 | + (indent-to-column bison-decl-token-column)) | ||
558 | + ((= section bison--grammar-rules-section) | ||
559 | + (indent-to-column | ||
560 | + (save-excursion | ||
561 | + (let* ((bound (or (save-excursion (bison--find-production-opener)) | ||
562 | + (bison--find-grammar-begin))) | ||
563 | + (prev-semi (search-backward ";" bound t)) | ||
564 | + ) | ||
565 | + (if prev-semi | ||
566 | + (if (bison--within-braced-c-expression-p section) ; CRACK | ||
567 | + bison-rule-enumeration-column | ||
568 | + 0) | ||
569 | + (if (save-excursion (bison--find-production-opener)) | ||
570 | + bison-rule-enumeration-column | ||
571 | + 0)))))) | ||
572 | + ((= section bison--c-code-section)) ;;leave-alone | ||
573 | + ))) | ||
574 | + | ||
575 | +(defun bison-indent-line () | ||
576 | + "Indent a line of bison code." | ||
577 | + (interactive) | ||
578 | + | ||
579 | + (let* ((pos (- (point-max) (point))) | ||
580 | + (reset-pt (function (lambda () | ||
581 | + (if (> (- (point-max) pos) (point)) | ||
582 | + (goto-char (- (point-max) pos)))))) | ||
583 | + (bol (save-excursion (beginning-of-line) (point))) | ||
584 | + (eol (save-excursion (end-of-line) (point))) | ||
585 | + ) | ||
586 | + (let* ((section (bison--section-p)) | ||
587 | + (c-sexp (bison--within-braced-c-expression-p section)) | ||
588 | + (ws-line (line-of-whitespace-p)) | ||
589 | + ) | ||
590 | + (cond | ||
591 | + ;; if you are a line of whitespace, let indent-new-line take care of it | ||
592 | + (ws-line | ||
593 | + (bison-indent-new-line c-sexp)) | ||
594 | + | ||
595 | + ((= section bison--pre-c-decls-section) | ||
596 | + ;; leave things alone | ||
597 | + ) | ||
598 | + | ||
599 | + ((= section bison--c-decls-section) | ||
600 | + (if c-sexp | ||
601 | + (bison--handle-indent-c-sexp section 0 bol) | ||
602 | + (if (not (= (current-indentation) 0)) | ||
603 | + (progn | ||
604 | + (back-to-indentation) | ||
605 | + (just-no-space) | ||
606 | + (funcall reset-pt))))) | ||
607 | + | ||
608 | + ((= section bison--bison-decls-section) | ||
609 | + (let ((opener (bison--bison-decl-opener-p bol eol))) | ||
610 | + (cond | ||
611 | + (opener | ||
612 | + (goto-char opener) | ||
613 | + (skip-chars-forward " \t" eol) | ||
614 | + (if (looking-at "{") | ||
615 | + (save-excursion | ||
616 | + (if (following-non-ws-p) | ||
617 | + (progn | ||
618 | + (forward-char 1) | ||
619 | + (just-no-space) | ||
620 | + (newline) | ||
621 | + (bison-indent-new-line t)))) | ||
622 | + (let ((complete-type t)) | ||
623 | + (if (looking-at "<") | ||
624 | + (progn | ||
625 | + (setq complete-type nil) | ||
626 | + (if (not (= (current-column) bison-decl-type-column)) | ||
627 | + (progn | ||
628 | + (just-no-space) | ||
629 | + (indent-to-column bison-decl-type-column)) | ||
630 | + (and (re-search-forward | ||
631 | + (concat "<" bison--word-constituent-re "+>") | ||
632 | + eol t) | ||
633 | + (setq complete-type t))))) | ||
634 | + (and complete-type | ||
635 | + (skip-chars-forward " \t" eol) | ||
636 | + (looking-at | ||
637 | + (concat "\\(" bison--word-constituent-re "\\|'\\)")) | ||
638 | + (if (not (= (current-column) bison-decl-token-column)) | ||
639 | + (progn | ||
640 | + (just-no-space) | ||
641 | + (indent-to-column bison-decl-token-column)))))) | ||
642 | + (funcall reset-pt)) | ||
643 | + (c-sexp | ||
644 | + (bison--handle-indent-c-sexp section 0 bol)) | ||
645 | + (t | ||
646 | + (back-to-indentation) | ||
647 | + ;; only tab in names, leave comments alone | ||
648 | + (cond (;; put word-constiuents in bison-decl-token-column | ||
649 | + (looking-at bison--word-constituent-re) | ||
650 | + (if (not (= (current-column) bison-decl-token-column)) | ||
651 | + (progn | ||
652 | + (just-no-space) | ||
653 | + (indent-to-column bison-decl-token-column)))) | ||
654 | + ;; put/keep close-brace in the 0 column | ||
655 | + ((looking-at "}") | ||
656 | + (if (not (= (current-column) 0)) | ||
657 | + (just-no-space))) | ||
658 | + ;; leave comments alone | ||
659 | + ((looking-at (regexp-quote comment-start)) nil) | ||
660 | + ;; else do nothing | ||
661 | + ) | ||
662 | + (funcall reset-pt))))) | ||
663 | + ((= section bison--grammar-rules-section) | ||
664 | + (cond | ||
665 | + ((bison--production-opener-p bol eol) | ||
666 | + (beginning-of-line) | ||
667 | + (re-search-forward bison--production-re);; SIGERR | ||
668 | + (if (following-non-ws-p) | ||
669 | + (if (> (current-column) bison-rule-enumeration-column) | ||
670 | + (progn | ||
671 | + (just-no-space) | ||
672 | + (newline) | ||
673 | + (indent-to-column bison-rule-enumeration-column)) | ||
674 | + (save-excursion | ||
675 | + (re-search-forward bison--word-constituent-re);; SIGERR | ||
676 | + (let ((col (current-column))) | ||
677 | + (cond ((> col (+ 1 bison-rule-enumeration-column)) | ||
678 | + (forward-char -1) | ||
679 | + (just-no-space) | ||
680 | + (indent-to-column bison-rule-enumeration-column)) | ||
681 | + ((< col (+ 1 bison-rule-enumeration-column)) | ||
682 | + (forward-char -1) | ||
683 | + (indent-to-column | ||
684 | + bison-rule-enumeration-column))))))) | ||
685 | + (funcall reset-pt)) | ||
686 | + ((bison--production-alternative-p bol eol section) | ||
687 | + (back-to-indentation);; should put point on "|" | ||
688 | + (if (not (= (current-column) bison-rule-separator-column)) | ||
689 | + (progn | ||
690 | + (just-no-space) | ||
691 | + (indent-to-column bison-rule-separator-column))) | ||
692 | + (forward-char 1) | ||
693 | + (if (following-non-ws-p) | ||
694 | + (save-excursion | ||
695 | + (re-search-forward bison--word-constituent-re);; SIGERR | ||
696 | + (let ((col (current-column))) | ||
697 | + (cond ((> col (+ 1 bison-rule-enumeration-column)) | ||
698 | + (forward-char -1) | ||
699 | + (just-no-space) | ||
700 | + (indent-to-column bison-rule-enumeration-column)) | ||
701 | + ((< col (+ 1 bison-rule-enumeration-column)) | ||
702 | + (forward-char -1) | ||
703 | + (indent-to-column | ||
704 | + bison-rule-enumeration-column)))))) | ||
705 | + (funcall reset-pt)) | ||
706 | + (c-sexp | ||
707 | + (bison--handle-indent-c-sexp | ||
708 | + section bison-rule-enumeration-column bol) | ||
709 | + (funcall reset-pt)) | ||
710 | + ((bison--within-production-body-p section) | ||
711 | + (back-to-indentation) | ||
712 | + (if (not (= (current-column) bison-rule-enumeration-column)) | ||
713 | + (progn | ||
714 | + (just-no-space) | ||
715 | + (indent-to-column | ||
716 | + bison-rule-enumeration-column))) | ||
717 | + (funcall reset-pt)) | ||
718 | + (t | ||
719 | + (let ((cur-ind (current-indentation))) | ||
720 | + (if (eq (save-excursion (search-backward "}" bol t)) | ||
721 | + cur-ind) | ||
722 | + (if (not (= cur-ind bison-rule-enumeration-column)) | ||
723 | + (progn | ||
724 | + (back-to-indentation) | ||
725 | + (just-no-space) | ||
726 | + (indent-to-column bison-rule-enumeration-column) | ||
727 | + (funcall reset-pt))) | ||
728 | + ;; else leave alone | ||
729 | + ))))) | ||
730 | + ((= section bison--c-code-section) | ||
731 | + (c-indent-line)) | ||
732 | + )))) | ||
733 | + | ||
734 | +;; *************** electric-functions *************** | ||
735 | + | ||
736 | +(defun bison-electric-colon (arg) | ||
737 | + "If the colon <:> delineates a production, | ||
738 | + then insert a semicolon on the next line in the BISON-RULE-SEPARATOR-COLUMN, | ||
739 | + put the cursor in the BISON-RULE-ENUMERATION-COLUMN for the beginning | ||
740 | + of the rule | ||
741 | + else just run self-insert-command | ||
742 | +A colon delineates a production by the fact that it is immediately preceded by | ||
743 | +a word(alphanumerics or '_''s), and there is no previous white space. | ||
744 | +" | ||
745 | + (interactive "P") | ||
746 | + | ||
747 | + (self-insert-command (prefix-numeric-value arg)) | ||
748 | + (if (and bison-electric-colon-v | ||
749 | + (not bison-all-electricity-off)) | ||
750 | + (if (and (= bison--grammar-rules-section (bison--section-p)) | ||
751 | + (bison--production-p) | ||
752 | + (not (bison--within-started-production-p))) | ||
753 | + (progn | ||
754 | + (save-excursion ; put in a closing semicolon | ||
755 | + (newline) | ||
756 | + (indent-to-column bison-rule-separator-column) | ||
757 | + (insert ";")) | ||
758 | + (save-excursion ; remove opening whitespace | ||
759 | + (if (re-search-backward | ||
760 | + "\\s " | ||
761 | + (save-excursion (beginning-of-line) (point)) | ||
762 | + t) | ||
763 | + (just-no-space))) | ||
764 | + (if (not (< (current-column) bison-rule-enumeration-column)) | ||
765 | + (newline)) | ||
766 | + (indent-to-column bison-rule-enumeration-column))))) | ||
767 | + | ||
768 | +(defun bison-electric-pipe (arg) | ||
769 | + "If the pipe <|> is used as a rule separator within a production, | ||
770 | + then move it into BISON-RULE-SEPARATOR-COLUMN | ||
771 | + indent to BISON-RULE-ENUMERATION-COLUMN on the same line | ||
772 | + else just run self-insert-command | ||
773 | +" | ||
774 | + (interactive "P") | ||
775 | + | ||
776 | + (if (and bison-electric-pipe-v | ||
777 | + (not bison-all-electricity-off) | ||
778 | + (= bison--grammar-rules-section (bison--section-p)) | ||
779 | + (line-of-whitespace-p) | ||
780 | + ) | ||
781 | + (progn | ||
782 | + (beginning-of-line) | ||
783 | + (just-no-space) | ||
784 | + (indent-to-column bison-rule-separator-column) | ||
785 | + (self-insert-command (prefix-numeric-value arg)) | ||
786 | + (indent-to-column bison-rule-enumeration-column) | ||
787 | + ) | ||
788 | + (self-insert-command (prefix-numeric-value arg)))) | ||
789 | + | ||
790 | +(defun bison-electric-open-brace (arg) | ||
791 | + "used for the opening brace of a C action definition for production rules, | ||
792 | +if there is only whitespace before \(point\), then put open-brace in | ||
793 | +bison-rule-enumeration-column" | ||
794 | + (interactive "P") | ||
795 | + | ||
796 | + (if (and bison-electric-open-brace-v | ||
797 | + (not bison-all-electricity-off)) | ||
798 | + (let ((section (bison--section-p))) | ||
799 | + (cond ((and (= section bison--grammar-rules-section) | ||
800 | + (not (bison--within-braced-c-expression-p section)) | ||
801 | + (not (previous-non-ws-p))) | ||
802 | + (if (not (= (current-column) bison-rule-enumeration-column)) | ||
803 | + (progn | ||
804 | + (just-no-space) | ||
805 | + (indent-to-column bison-rule-enumeration-column)))) | ||
806 | + ((and (= section bison--bison-decls-section) | ||
807 | + (not (bison--within-braced-c-expression-p section)) | ||
808 | + (not (previous-non-ws-p))) | ||
809 | + (if (not (= (current-column) 0)) | ||
810 | + (progn | ||
811 | + (just-no-space) | ||
812 | + (indent-to-column 0))))))) | ||
813 | + | ||
814 | + (self-insert-command (prefix-numeric-value arg))) | ||
815 | + | ||
816 | + | ||
817 | +(defun bison-electric-close-brace (arg) | ||
818 | + "If the close-brace \"}\" is used as the c-declarations section closer | ||
819 | +in \"%}\", then make sure the \"%}\" indents to the beginning of the line" | ||
820 | + (interactive "P") | ||
821 | + | ||
822 | + (self-insert-command (prefix-numeric-value arg)) | ||
823 | + | ||
824 | + (if (and bison-electric-close-brace-v | ||
825 | + (not bison-all-electricity-off)) | ||
826 | + (cond ((search-backward "%}" (- (point) 2) t) | ||
827 | + (if (= (bison--section-p) bison--c-decls-section) | ||
828 | + (progn | ||
829 | + (just-no-space) | ||
830 | + (forward-char 2)) ; for "%}" | ||
831 | + (forward-char 1))) | ||
832 | + ))) | ||
833 | + | ||
834 | +(defun bison-electric-semicolon (arg) | ||
835 | + "if the semicolon is used to end a production, then place it in | ||
836 | +bison-rule-separator-column | ||
837 | + | ||
838 | +a semicolon is deemed to be used for ending a production if it is not found | ||
839 | +within braces | ||
840 | + | ||
841 | +this is just self-insert-command as i have yet to write the actual | ||
842 | +bison-electric-semicolon function yet | ||
843 | +" | ||
844 | + (interactive "P") | ||
845 | + | ||
846 | + (self-insert-command (prefix-numeric-value arg))) | ||
847 | + | ||
848 | +(defun bison-electric-percent (arg) | ||
849 | + "If the percent is a declarer in the bison declaration's section, | ||
850 | +then put it in the 0 column." | ||
851 | + (interactive "P") | ||
852 | + | ||
853 | + (if (and bison-electric-percent-v | ||
854 | + (not bison-all-electricity-off)) | ||
855 | + (let ((section (bison--section-p))) | ||
856 | + (if (and (= section bison--bison-decls-section) | ||
857 | + (not (bison--within-braced-c-expression-p section)) | ||
858 | + (not (previous-non-ws-p)) | ||
859 | + (not (= (current-column) 0))) | ||
860 | + (just-no-space)))) | ||
861 | + | ||
862 | + (self-insert-command (prefix-numeric-value arg))) | ||
863 | + | ||
864 | +(defun bison-electric-less-than (arg) | ||
865 | + "If the less-than is a type declarer opener for tokens in the bison | ||
866 | +declaration section, then put it in the bison-decl-type-column column." | ||
867 | + (interactive "P") | ||
868 | + | ||
869 | + (if (and bison-electric-less-than-v | ||
870 | + (not bison-all-electricity-off)) | ||
871 | + (if (and (= (bison--section-p) bison--bison-decls-section) | ||
872 | + (bison--bison-decl-opener-p | ||
873 | + (save-excursion (beginning-of-line) (point)) | ||
874 | + (point))) | ||
875 | + (progn | ||
876 | + (just-no-space) | ||
877 | + (indent-to-column bison-decl-type-column)))) | ||
878 | + | ||
879 | + (self-insert-command (prefix-numeric-value arg))) | ||
880 | + | ||
881 | +(defun bison-electric-greater-than (arg) | ||
882 | + "If the greater-than is a type declarer closer for tokens in the bison | ||
883 | +declaration section, then indent to bison-decl-token-column." | ||
884 | + (interactive "P") | ||
885 | + | ||
886 | + (self-insert-command (prefix-numeric-value arg)) | ||
887 | + | ||
888 | + (if (and bison-electric-greater-than-v | ||
889 | + (not bison-all-electricity-off)) | ||
890 | + (let ((current-pt (point)) | ||
891 | + (bol (save-excursion (beginning-of-line) (point)))) | ||
892 | + (if (and (= (bison--section-p) bison--bison-decls-section) | ||
893 | + (bison--bison-decl-opener-p bol (point))) | ||
894 | + (if (search-backward "<" bol t) | ||
895 | + (if (re-search-forward | ||
896 | + (concat "<" bison--word-constituent-re "+>") | ||
897 | + current-pt t) | ||
898 | + (if (not (following-non-ws-p)) | ||
899 | + (progn | ||
900 | + (just-no-space) | ||
901 | + (indent-to-column bison-decl-token-column))))))))) | ||
902 | + | ||
903 | +;;;###autoload | ||
904 | +(define-derived-mode jison-mode bison-mode | ||
905 | + "Major mode for editing jison files.") | ||
906 | + | ||
907 | +(provide 'bison-mode) | ||
908 | +(provide 'jison-mode) | ||
909 | +;;; bison-mode.el ends here |
elpa/bison-mode-20160616.2252/bison-mode.elc
0 → 100644
No preview for this file type
-
Please register or login to post a comment