subword-mode-expansions.el (1798B)
1 ;;; subword-mode-expansions.el --- Expansions for subword-mode to be used for CamelCase -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2014-2023 Free Software Foundation, Inc 4 5 ;; Author: Lefteris Karapetsas 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 ;; Provides extra expansions for subword mode so that when 24 ;; subword-mode is non-nil different words can be selected in CamelCase. 25 ;; Feel free to contribute any other expansions: 26 ;; 27 ;; https://github.com/magnars/expand-region.el 28 29 ;;; Code: 30 31 (require 'expand-region-core) 32 (require 'subword) 33 34 (defun er/mark-subword () 35 "Mark a subword, a part of a CamelCase identifier." 36 (interactive) 37 (when (and subword-mode 38 expand-region-subword-enabled) 39 (subword-right 1) 40 (set-mark (point)) 41 (subword-left 1))) 42 43 (defun er/add-subword-mode-expansions () 44 "Add expansions for buffers in `subword-mode'." 45 (set (make-local-variable 'er/try-expand-list) 46 (append er/try-expand-list 47 '(er/mark-subword)))) 48 49 (er/enable-minor-mode-expansions 'subword-mode 'er/add-subword-mode-expansions) 50 51 (provide 'subword-mode-expansions) 52 ;;; subword-mode-expansions.el ends here