cperl-mode-expansions.el (2268B)
1 ;;; cperl-mode-expansions.el --- perl-specific expansions for expand-region -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2012-2023 Free Software Foundation, Inc 4 5 ;; Author: Kang-min Liu <gugod@gugod.org> 6 ;; Keywords: marking region cperl 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 ;;; Code: 22 23 (require 'expand-region-core) 24 25 (defun er/mark-cperl-variable-name () 26 "Marks one perl variable" 27 (interactive) 28 (forward-word) 29 (backward-word) 30 (search-backward-regexp "[@$%]" (line-beginning-position)) 31 (set-mark (point)) 32 (forward-char) 33 (search-forward-regexp "[^a-z_]" (line-end-position)) 34 (backward-char) 35 (exchange-point-and-mark)) 36 37 (defun er/mark-cperl-package-name () 38 "Marks one perl package name" 39 (interactive) 40 (forward-sexp) 41 (backward-sexp) 42 (set-mark (point)) 43 (forward-sexp) 44 (search-backward "::" (line-beginning-position)) 45 (exchange-point-and-mark)) 46 47 (defun er/mark-cperl-subroutine () 48 "Marks current subroutine body." 49 (interactive) 50 (end-of-defun) 51 (set-mark (point)) 52 (beginning-of-defun)) 53 54 (defun er/add-cperl-mode-expansions () 55 "Add cprel mode expansinos" 56 (set (make-local-variable 'er/try-expand-list) (append 57 er/try-expand-list 58 '(er/mark-cperl-variable-name 59 er/mark-cperl-package-name 60 er/mark-cperl-subroutine 61 )))) 62 63 (er/enable-mode-expansions 'cperl-mode #'er/add-cperl-mode-expansions) 64 65 (provide 'cperl-mode-expansions) 66 67 ;; cperl-mode-expansions.el ends here