dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

text-mode-expansions.el (2174B)


      1 ;;; text-mode-expansions.el --- Expansions for expand-region to be used in text
      2 
      3 ;; Copyright (C) 2012-2020  Free Software Foundation, Inc
      4 
      5 ;; Author: Ivan Andrus
      6 ;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
      7 ;; Keywords: marking region
      8 
      9 ;; This program is free software; you can redistribute it and/or modify
     10 ;; it under the terms of the GNU General Public License as published by
     11 ;; the Free Software Foundation, either version 3 of the License, or
     12 ;; (at your option) any later version.
     13 
     14 ;; This program is distributed in the hope that it will be useful,
     15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 ;; GNU General Public License for more details.
     18 
     19 ;; You should have received a copy of the GNU General Public License
     20 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 ;;; Commentary:
     23 
     24 ;; Feel free to contribute any other expansions for normal text at
     25 ;;
     26 ;;     https://github.com/magnars/expand-region.el
     27 
     28 ;;; Code:
     29 
     30 (require 'expand-region-core)
     31 
     32 (defun er/mark-text-sentence ()
     33   "Marks one sentence."
     34   (interactive)
     35   ;; The obvious
     36   ;; (backward-sentence 1) (mark-end-of-sentence 1)
     37   ;; doesn't work here because it's repeated and the selection keeps
     38   ;; growing by sentences, which isn't what's wanted.
     39   (forward-sentence 1)
     40   (set-mark (point))
     41   (backward-sentence 1))
     42 
     43 (defun er/mark-text-paragraph ()
     44   "Marks one paragraph."
     45   (interactive)
     46   (mark-paragraph)
     47   (skip-chars-forward er--space-str))
     48 
     49 (defun er/add-text-mode-expansions ()
     50   "Adds expansions for buffers in `text-mode' except for `html-mode'.
     51 Unfortunately `html-mode' inherits from `text-mode' and
     52 text-mode-expansions don't work well in `html-mode'."
     53   (unless (member major-mode expand-region-exclude-text-mode-expansions)
     54     (set (make-local-variable 'er/try-expand-list)
     55          (append
     56           er/try-expand-list
     57           '(er/mark-text-sentence
     58             er/mark-text-paragraph
     59             mark-page)))))
     60 
     61 (er/enable-mode-expansions 'text-mode 'er/add-text-mode-expansions)
     62 
     63 (provide 'text-mode-expansions)
     64 
     65 ;; text-mode-expansions.el ends here