/ jsp-expansions.el
jsp-expansions.el
 1  ;;; jsp-expansions.el --- JSP-specific expansions for expand-region  -*- lexical-binding: t; -*-
 2  
 3  ;; Copyright (C) 2011-2023  Free Software Foundation, Inc
 4  
 5  ;; Author: Magnar Sveen <magnars@gmail.com>
 6  ;; Keywords: marking region
 7  
 8  ;; This program is free software; you can redistribute it and/or modify
 9  ;; it under the terms of the GNU General Public License as published by
10  ;; the Free Software Foundation, either version 3 of the License, or
11  ;; (at your option) any later version.
12  
13  ;; This program is distributed in the hope that it will be useful,
14  ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15  ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  ;; GNU General Public License for more details.
17  
18  ;; You should have received a copy of the GNU General Public License
19  ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  
21  ;;; Commentary:
22  
23  ;; Extra expansions for editing JSP files. To be used in conjunction
24  ;; with the html-mode expansions
25  ;;
26  ;;     er/mark-jstl-escape
27  ;;
28  ;; These expansions aren't loaded by default, so you'll have to explicitly
29  ;; ask for them in your init file with:
30  ;;
31  ;;     (eval-after-load 'sgml-mode '(require 'jsp-expansions))
32  ;;
33  ;; Feel free to contribute any other expansions for JSP at
34  ;;
35  ;;     https://github.com/magnars/expand-region.el
36  
37  ;;; Code:
38  
39  (require 'expand-region-core)
40  
41  (defun er/mark-jstl-escape ()
42      "Mark jstl-escape presumes that point is outside the brackets.
43  If point is inside the brackets, they will be marked first anyway."
44      (interactive)
45        (when (or (looking-at "\\${")
46              (er/looking-back-exact "$"))
47      (forward-char 1)
48      (search-backward "\$")
49      (set-mark (point))
50      (forward-char 1)
51      (forward-list)
52      (exchange-point-and-mark)))
53  
54  (defun er/add-jsp-expansions ()
55    "Adds JSP-specific expansions to the buffer"
56    (set (make-local-variable 'er/try-expand-list) (append
57                                                    er/try-expand-list
58                                                    '(er/mark-jstl-escape))))
59  
60  (er/enable-mode-expansions 'html-mode #'er/add-jsp-expansions)
61  
62  (provide 'jsp-expansions)
63  
64  ;; jsp-expansions.el ends here