diff --git a/expreg.el b/expreg.el index 05459af..2147ce8 100644 --- a/expreg.el +++ b/expreg.el @@ -1,6 +1,6 @@ ;;; expreg.el --- Simple expand region -*- lexical-binding: t; -*- -;; Copyright (C) 2022 Free Software Foundation, Inc. +;; Copyright (C) 2022, 2023 Free Software Foundation, Inc. ;; ;; Author: Yuan Fu ;; Maintainer: Yuan Fu @@ -79,8 +79,8 @@ (require 'subword) (require 'treesit) (eval-when-compile - (require 'cl-lib) - (require 'seq)) + (require 'cl-lib)) +(require 'seq) ;;; Cutom options and variables @@ -102,9 +102,9 @@ scan-error, like end-of-buffer, or unbalanced parentheses, etc.") (defun expreg--sort-regions (regions) "Sort REGIONS by their span." - (cl-sort regions (lambda (a b) - (< (- (cddr a) (cadr a)) - (- (cddr b) (cadr b)))))) + (sort regions (lambda (a b) + (< (- (cddr a) (cadr a)) + (- (cddr b) (cadr b)))))) (defvar expreg--validation-white-list '(list-at-point) "Regions produced by functions in this list skips filtering.") @@ -166,12 +166,11 @@ ORIG is the current position. Each region is (BEG . END)." ;; OTOH, if there are regions that ends at ORIG, filter out ;; regions that starts AFTER ORIGN, eg, special cases in ;; ‘expreg--list-at-point’. - (setq regions (cl-remove-if - (lambda (region) - (and orig-at-end-of-something - (> (cadr region) orig))) - regions)) - regions)) + (cl-remove-if + (lambda (region) + (and orig-at-end-of-something + (> (cadr region) orig))) + regions))) ;;; Syntax-ppss shorthands @@ -199,7 +198,7 @@ POS defaults to point." ;;; Expand/contract (defvar-local expreg--verbose nil - "If t, print debugging information.") + "Non-nil means print debugging information.") (defvar-local expreg--next-regions nil "The regions we are going to expand to. @@ -209,12 +208,13 @@ This should be a list of (BEG . END).") "The regions we’ve expanded past. This should be a list of (BEG . END).") +;;;###autoload (defun expreg-expand () "Expand region." (interactive) ;; Checking for last-command isn’t strictly necessary, but nice to ;; have. - (when (not (and (region-active-p) + (when (not (and (use-region-p) (eq (region-beginning) (cadr (car expreg--prev-regions))) (eq (region-end) @@ -236,7 +236,7 @@ This should be a list of (BEG . END).") ;; Go past all the regions that are smaller than the current region, ;; if region is active. - (when (region-active-p) + (when (use-region-p) (while (and expreg--next-regions (let ((beg (cadr (car expreg--next-regions))) (end (cddr (car expreg--next-regions)))) @@ -261,8 +261,8 @@ This should be a list of (BEG . END).") (defun expreg-contract () "Contract region." (interactive) - (when (and (region-active-p) - (> (length expreg--prev-regions) 1)) + (when (and (use-region-p) + (length> expreg--prev-regions 1)) (push (pop expreg--prev-regions) expreg--next-regions) (set-mark (cddr (car expreg--prev-regions))) @@ -548,7 +548,7 @@ current string/comment and get lists inside." (defun expreg--comment () "Return a list of regions containing comment." (let ((orig (point)) - (beg (point)) + (beg (point)) ;perhaps use narrowing? (end (point)) result forward-succeeded trailing-comment-p)