[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/expand-region 8493232800: Update code for lexical-bindi
From: |
Stefan Monnier |
Subject: |
[elpa] externals/expand-region 8493232800: Update code for lexical-binding, cl-lib, and advice-add |
Date: |
Sun, 15 Oct 2023 15:12:02 -0400 (EDT) |
branch: externals/expand-region
commit 849323280027035b693f727f7119faaa186a54d2
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
Update code for lexical-binding, cl-lib, and advice-add
Activate `lexical-binding`. Use `advice-add` rather than `defadvice`.
Avoid deprectaed `point-at-bol/eol`. Prefer #' to quote function names.
Fix a few docstrings to silence compiler warnings.
* cc-mode-expansions.el (er/c-define-construct): Fix ' in docstring.
* enh-ruby-mode-expansions.el: Require `expand-region-core`.
* er-basic-expansions.el (er/mark-next-accessor): Remove unused var
`symbol-regexp`.
* expand-region-core.el: Don't require `cl`.
(er--show-expansion-message): Declare it.
(er--first-invocation): Move before first use.
(er--expand-region-1): Remove unused var `set-mark-default-inactive`.
(er/set-temporary-overlay-map): Hoist definition outside of `if`.
* expand-region-custom.el (expand-region-preferred-python-mode): Fix
custom type.
* expand-region.el: Explicitly require Emacs-24.4.
* js-mode-expansions.el: Require `er-basic-expansions`.
* ruby-mode-expansions.el (expand-region-core): Require `cl-lib` rather
than `cl`. Require `er-basic-expansions`.
(er/ruby-backward-up): Use `cl-loop`.
(er/get-ruby-block): Remove unused vars `beg` and `end`.
* the-org-mode-expansions.el (er-basic-expansions):
Require `er-basic-expansions`.
* yaml-mode-expansions.el: Re-add now that the author signed the paperwork.
---
cc-mode-expansions.el | 20 +--
clojure-mode-expansions.el | 8 +-
cperl-mode-expansions.el | 6 +-
css-mode-expansions.el | 6 +-
enh-ruby-mode-expansions.el | 8 +-
er-basic-expansions.el | 10 +-
erlang-mode-expansions.el | 6 +-
expand-region-core.el | 52 +++---
expand-region-custom.el | 20 +--
expand-region.el | 10 +-
feature-mode-expansions.el | 6 +-
features/step-definitions/expand-region-steps.el | 2 +-
features/support/env.el | 2 +-
html-mode-expansions.el | 17 +-
js-mode-expansions.el | 17 +-
js2-mode-expansions.el | 6 +-
jsp-expansions.el | 6 +-
latex-mode-expansions.el | 6 +-
nxml-mode-expansions.el | 6 +-
octave-expansions.el | 6 +-
python-el-expansions.el | 6 +-
python-el-fgallina-expansions.el | 12 +-
python-mode-expansions.el | 8 +-
ruby-mode-expansions.el | 59 ++++---
sml-mode-expansions.el | 6 +-
subword-mode-expansions.el | 4 +-
text-mode-expansions.el | 6 +-
the-org-mode-expansions.el | 7 +-
web-mode-expansions.el | 6 +-
yaml-mode-expansions.el | 194 +++++++++++++++++++++++
30 files changed, 361 insertions(+), 167 deletions(-)
diff --git a/cc-mode-expansions.el b/cc-mode-expansions.el
index 73713cf1a2..126b7f19e0 100644
--- a/cc-mode-expansions.el
+++ b/cc-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; cc-mode-expansions.el --- C-specific expansions for expand-region
+;;; cc-mode-expansions.el --- C-specific expansions for expand-region -*-
lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: François Févotte
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -119,7 +119,7 @@ This function captures identifiers composed of multiple
doc "\n\n"
"This function tries to mark a region consisting of two parts:\n"
(format " - the first part is marked using `%s'\n" (symbol-name
mark-first-part))
- (format " - the second part is a block beginning with '%s'\n\n"
open-brace)))
+ (format " - the second part is a block beginning with %S\n\n"
open-brace)))
`(progn
(defun ,(intern (concat (symbol-name name) "-1")) ()
,(concat docstring
@@ -173,13 +173,13 @@ This function captures identifiers composed of multiple
er/c-mark-statement-block-1 er/c-mark-statement-block-2
er/c-mark-vector-access-1 er/c-mark-vector-access-2))))
-(er/enable-mode-expansions 'c-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'c++-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'objc-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'java-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'idl-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'pike-mode 'er/add-cc-mode-expansions)
-(er/enable-mode-expansions 'awk-mode 'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'c-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'c++-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'objc-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'java-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'idl-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'pike-mode #'er/add-cc-mode-expansions)
+(er/enable-mode-expansions 'awk-mode #'er/add-cc-mode-expansions)
(provide 'cc-mode-expansions)
diff --git a/clojure-mode-expansions.el b/clojure-mode-expansions.el
index 73bcabef50..17c75d20ad 100644
--- a/clojure-mode-expansions.el
+++ b/clojure-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; clojure-mode-expansions.el --- Clojure-specific expansions for
expand-region
+;;; clojure-mode-expansions.el --- Clojure-specific expansions for
expand-region -*- lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -98,8 +98,8 @@ If point is inside the parens, they will be marked first
anyway."
er/mark-clj-set-literal
er/mark-clj-function-literal))))
-(er/enable-mode-expansions 'clojure-mode 'er/add-clojure-mode-expansions)
-(er/enable-mode-expansions 'nrepl-mode 'er/add-clojure-mode-expansions)
+(er/enable-mode-expansions 'clojure-mode #'er/add-clojure-mode-expansions)
+(er/enable-mode-expansions 'nrepl-mode #'er/add-clojure-mode-expansions)
(provide 'clojure-mode-expansions)
diff --git a/cperl-mode-expansions.el b/cperl-mode-expansions.el
index 59a3809c0f..b9e4e2e47e 100644
--- a/cperl-mode-expansions.el
+++ b/cperl-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; cperl-mode-expansions.el --- perl-specific expansions for expand-region
+;;; cperl-mode-expansions.el --- perl-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Kang-min Liu <gugod@gugod.org>
;; Keywords: marking region cperl
@@ -60,7 +60,7 @@
er/mark-cperl-subroutine
))))
-(er/enable-mode-expansions 'cperl-mode 'er/add-cperl-mode-expansions)
+(er/enable-mode-expansions 'cperl-mode #'er/add-cperl-mode-expansions)
(provide 'cperl-mode-expansions)
diff --git a/css-mode-expansions.el b/css-mode-expansions.el
index 0db4c6a702..3ab14cb32c 100644
--- a/css-mode-expansions.el
+++ b/css-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; css-mode-expansions.el --- CSS-specific expansions for expand-region
+;;; css-mode-expansions.el --- CSS-specific expansions for expand-region -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -45,7 +45,7 @@
er/try-expand-list
'(er/mark-css-declaration))))
-(er/enable-mode-expansions 'css-mode 'er/add-css-mode-expansions)
+(er/enable-mode-expansions 'css-mode #'er/add-css-mode-expansions)
(provide 'css-mode-expansions)
diff --git a/enh-ruby-mode-expansions.el b/enh-ruby-mode-expansions.el
index dfaefdf565..4e26802d73 100644
--- a/enh-ruby-mode-expansions.el
+++ b/enh-ruby-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; enh-ruby-mode-expansions.el --- Expansions for enh-ruby-mode
+;;; enh-ruby-mode-expansions.el --- Expansions for enh-ruby-mode -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -28,6 +28,8 @@
;;; Code:
+(require 'expand-region-core)
+
(defun er/add-enh-ruby-mode-expansions ()
"Adds Ruby-specific expansions for buffers in enh-ruby-mode"
(require 'ruby-mode-expansions)
@@ -37,6 +39,6 @@
'(er/mark-ruby-instance-variable
er/mark-ruby-block-up))))
-(er/enable-mode-expansions 'enh-ruby-mode 'er/add-enh-ruby-mode-expansions)
+(er/enable-mode-expansions 'enh-ruby-mode #'er/add-enh-ruby-mode-expansions)
(provide 'enh-ruby-mode-expansions)
diff --git a/er-basic-expansions.el b/er-basic-expansions.el
index 2da114d3a5..2e771a5a55 100644
--- a/er-basic-expansions.el
+++ b/er-basic-expansions.el
@@ -1,6 +1,6 @@
-;;; er-basic-expansions.el --- Words, symbols, strings, et al
+;;; er-basic-expansions.el --- Words, symbols, strings, et al -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -69,11 +69,11 @@ period and marks next symbol."
(when (use-region-p)
(when (< (point) (mark))
(exchange-point-and-mark))
- (let ((symbol-regexp "\\s_\\|\\sw"))
+ ;; (let ((symbol-regexp "\\s_\\|\\sw"))
(when (looking-at "\\.")
(forward-char 1)
(skip-syntax-forward "_w")
- (exchange-point-and-mark)))))
+ (exchange-point-and-mark)))) ;; )
(defun er/mark-method-call ()
"Mark the current symbol (including dots) and then paren to closing paren."
@@ -116,7 +116,7 @@ period and marks next symbol."
"The char that is the current quote delimiter"
(nth 3 (syntax-ppss)))
-(defalias 'er--point-inside-string-p 'er--current-quotes-char)
+(defalias 'er--point-inside-string-p #'er--current-quotes-char)
(defun er--move-point-forward-out-of-string ()
"Move point forward until it exits the current quoted string."
diff --git a/erlang-mode-expansions.el b/erlang-mode-expansions.el
index 9f0ec3c42f..9970c5d344 100644
--- a/erlang-mode-expansions.el
+++ b/erlang-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; erlang-mode-expansions.el --- Erlang-specific expansions for expand-region
+;;; erlang-mode-expansions.el --- Erlang-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Gleb Peregud
;; Based on python-mode-expansions by: Ivan Andrus <darthandrus@gmail.com>
@@ -40,7 +40,7 @@
'(erlang-mark-function
erlang-mark-clause))))
-(er/enable-mode-expansions 'erlang-mode 'er/add-erlang-mode-expansions)
+(er/enable-mode-expansions 'erlang-mode #'er/add-erlang-mode-expansions)
(provide 'erlang-mode-expansions)
diff --git a/expand-region-core.el b/expand-region-core.el
index 4171d02691..3a19a7bcc0 100644
--- a/expand-region-core.el
+++ b/expand-region-core.el
@@ -1,6 +1,6 @@
-;;; expand-region-core.el --- Increase selected region by semantic units.
+;;; expand-region-core.el --- Increase selected region by semantic units. -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -26,7 +26,6 @@
;;; Code:
-(eval-when-compile (require 'cl))
(require 'expand-region-custom)
(declare-function er/expand-region "expand-region")
@@ -39,7 +38,7 @@
(defvar er--space-str " \t\n")
(defvar er--blank-list (append er--space-str nil))
-(set-default 'er--show-expansion-message nil)
+(defvar er--show-expansion-message nil)
(defvar er/try-expand-list nil
"A list of functions that are tried when expanding.")
@@ -47,6 +46,10 @@
(defvar er/save-mode-excursion nil
"A function to save excursion state when expanding.")
+(defsubst er--first-invocation ()
+ "t if this is the first invocation of `er/expand-region' or
`er/contract-region'."
+ (not (memq last-command '(er/expand-region er/contract-region))))
+
(defun er--prepare-expanding ()
(when (and (er--first-invocation)
(not (use-region-p)))
@@ -87,11 +90,12 @@ moving point or mark as little as possible."
(try-list er/try-expand-list)
(best-start (point-min))
(best-end (point-max))
- (set-mark-default-inactive nil))
+ ;; (set-mark-default-inactive nil)
+ )
;; add hook to clear history on buffer changes
(unless er/history
- (add-hook 'after-change-functions 'er/clear-history t t))
+ (add-hook 'after-change-functions #'er/clear-history t t))
;; remember the start and end points so we can contract later
;; unless we're already at maximum size
@@ -215,10 +219,11 @@ before calling `er/expand-region' for the first time."
t)
(or (minibufferp) (message "%s" msg)))))
-(if (fboundp 'set-temporary-overlay-map)
- (fset 'er/set-temporary-overlay-map 'set-temporary-overlay-map)
- ;; Backport this function from newer emacs versions
- (defun er/set-temporary-overlay-map (map &optional keep-pred)
+(defalias 'er/set-temporary-overlay-map
+ (if (fboundp 'set-temporary-overlay-map) ;Emacs≥24.3
+ #'set-temporary-overlay-map
+ ;; Backport this function from newer emacs versions
+ (lambda (map &optional keep-pred)
"Set a new keymap that will only exist for a short period of time.
The new keymap to use must be given in the MAP variable. When to
remove the keymap depends on user input and KEEP-PRED:
@@ -252,29 +257,28 @@ remove the keymap depends on user input and KEEP-PRED:
(fset clearfunsym clearfun)
(add-hook 'pre-command-hook clearfunsym)
- (push alist emulation-mode-map-alists))))
+ (push alist emulation-mode-map-alists)))))
-(defadvice keyboard-quit (before collapse-region activate)
+(advice-add 'keyboard-quit :before #'er--collapse-region-before)
+(advice-add 'cua-cancel :before #'er--collapse-region-before)
+(defun er--collapse-region-before (&rest _)
+ ;; FIXME: Re-use `er--first-invocation'?
(when (memq last-command '(er/expand-region er/contract-region))
(er/contract-region 0)))
-(defadvice minibuffer-keyboard-quit (around collapse-region activate)
+(advice-add 'minibuffer-keyboard-quit
+ :around #'er--collapse-region-minibuffer-keyboard-quit)
+(defun er--collapse-region-minibuffer-keyboard-quit (orig-fun &rest args)
+ ;; FIXME: Re-use `er--first-invocation'?
(if (memq last-command '(er/expand-region er/contract-region))
(er/contract-region 0)
- ad-do-it))
+ (apply orig-fun args)))
-(defadvice cua-cancel (before collapse-region activate)
- (when (memq last-command '(er/expand-region er/contract-region))
- (er/contract-region 0)))
-(defun er/clear-history (&rest args)
+(defun er/clear-history (&rest _)
"Clear the history."
(setq er/history '())
- (remove-hook 'after-change-functions 'er/clear-history t))
-
-(defsubst er--first-invocation ()
- "t if this is the first invocation of er/expand-region or er/contract-region"
- (not (memq last-command '(er/expand-region er/contract-region))))
+ (remove-hook 'after-change-functions #'er/clear-history t))
(defun er--point-is-surrounded-by-white-space ()
(and (or (memq (char-before) er--blank-list)
@@ -283,7 +287,7 @@ remove the keymap depends on user input and KEEP-PRED:
(defun er/enable-mode-expansions (mode add-fn)
(add-hook (intern (format "%s-hook" mode)) add-fn)
- (save-window-excursion
+ (save-window-excursion ;; FIXME: Why?
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p mode)
diff --git a/expand-region-custom.el b/expand-region-custom.el
index ff87587d14..51cdb16ba6 100644
--- a/expand-region-custom.el
+++ b/expand-region-custom.el
@@ -1,6 +1,6 @@
-;;; expand-region-custom.el --- Increase selected region by semantic units.
+;;; expand-region-custom.el --- Increase selected region by semantic units.
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -32,15 +32,13 @@
;;;###autoload
(defcustom expand-region-preferred-python-mode 'python
"The name of your preferred python mode"
- :group 'expand-region
- :type '(choice (const :tag "Emacs' python.el" 'python)
- (const :tag "fgallina's python.el" 'fgallina-python)
- (const :tag "python-mode.el" 'python-mode)))
+ :type '(choice (const :tag "Emacs' python.el" python)
+ (const :tag "fgallina's python.el" fgallina-python)
+ (const :tag "python-mode.el" python-mode)))
;;;###autoload
(defcustom expand-region-guess-python-mode t
"If expand-region should attempt to guess your preferred python mode"
- :group 'expand-region
:type '(choice (const :tag "Guess" t)
(const :tag "Do not guess" nil)))
@@ -56,40 +54,34 @@
"If set to a string of a single character (try \"e\"), then the
contents of the most recent expand or contract command will
always be copied to the register named after that character."
- :group 'expand-region
:type 'string)
;;;###autoload
(defcustom expand-region-skip-whitespace t
"If expand-region should skip past whitespace on initial expansion"
- :group 'expand-region
:type '(choice (const :tag "Skip whitespace" t)
(const :tag "Do not skip whitespace" nil)))
;;;###autoload
(defcustom expand-region-fast-keys-enabled t
"If expand-region should bind fast keys after initial expand/contract"
- :group 'expand-region
:type '(choice (const :tag "Enable fast keys" t)
(const :tag "Disable fast keys" nil)))
;;;###autoload
(defcustom expand-region-contract-fast-key "-"
"Key to use after an initial expand/contract to contract once more."
- :group 'expand-region
:type 'string)
;;;###autoload
(defcustom expand-region-reset-fast-key "0"
"Key to use after an initial expand/contract to undo."
- :group 'expand-region
:type 'string)
;;;###autoload
(defcustom expand-region-exclude-text-mode-expansions
'(html-mode nxml-mode)
"List of modes which derive from `text-mode' for which text mode expansions
are not appropriate."
- :group 'expand-region
:type '(repeat (symbol :tag "Major Mode" unknown)))
;;;###autoload
@@ -100,7 +92,6 @@ If set to t, and the cursor is already at the beginning of
the new region,
keep it there; otherwise, put it at the end of the region.
If set to nil, always place the cursor at the beginning of the region."
- :group 'expand-region
:type '(choice (const :tag "Smart behaviour" t)
(const :tag "Standard behaviour" nil)))
@@ -111,7 +102,6 @@ If set to nil, always place the cursor at the beginning of
the region."
;;;###autoload
(defcustom expand-region-subword-enabled nil
"Whether expand-region should use subword expansions."
- :group 'expand-region
:type '(choice (const :tag "Enable subword expansions" t)
(const :tag "Disable subword expansions" nil)))
diff --git a/expand-region.el b/expand-region.el
index c6fcbd7226..8e218d346f 100644
--- a/expand-region.el
+++ b/expand-region.el
@@ -1,11 +1,12 @@
-;;; expand-region.el --- Increase selected region by semantic units.
+;;; expand-region.el --- Increase selected region by semantic units. -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
;; URL: https://github.com/magnars/expand-region.el
;; Version: 0.11.0
+;; Package-Requires: ((emacs "24.4"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -82,13 +83,12 @@
;; `mark-page`. To add it to the try-list, do this:
;; (defun er/add-text-mode-expansions ()
-;; (make-variable-buffer-local 'er/try-expand-list)
-;; (setq er/try-expand-list (append
+;; (setq-local er/try-expand-list (append
;; er/try-expand-list
;; '(mark-paragraph
;; mark-page))))
-;; (er/enable-mode-expansions 'text-mode 'er/add-text-mode-expansions)
+;; (er/enable-mode-expansions 'text-mode #'er/add-text-mode-expansions)
;; Add that to its own file, and require it at the bottom of this one,
;; where it says "Mode-specific expansions"
diff --git a/feature-mode-expansions.el b/feature-mode-expansions.el
index 18a36543d0..a92cec2265 100644
--- a/feature-mode-expansions.el
+++ b/feature-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; feature-mode-expansions.el --- cucumber-specific expansions for
expand-region
+;;; feature-mode-expansions.el --- cucumber-specific expansions for
expand-region -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Raimon Grau
;; Based on js-mode-expansions by: Raimon Grau <raimonster@gmail.com>
@@ -63,6 +63,6 @@
'(er/mark-feature-scenario
er/mark-feature-step))))
-(er/enable-mode-expansions 'feature-mode 'er/add-feature-mode-expansions)
+(er/enable-mode-expansions 'feature-mode #'er/add-feature-mode-expansions)
(provide 'feature-mode-expansions)
diff --git a/features/step-definitions/expand-region-steps.el
b/features/step-definitions/expand-region-steps.el
index 107498aa76..6f0d8872d9 100644
--- a/features/step-definitions/expand-region-steps.el
+++ b/features/step-definitions/expand-region-steps.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc -*-
lexical-binding: t; -*-
(Given "^mark is inactive by default$"
(lambda ()
diff --git a/features/support/env.el b/features/support/env.el
index 83d0fbfec0..00aa858a3f 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc -*-
lexical-binding: t; -*-
(let* ((current-directory (file-name-directory load-file-name))
(features-directory (expand-file-name ".." current-directory))
diff --git a/html-mode-expansions.el b/html-mode-expansions.el
index 1ca75522bc..19b4d028ee 100644
--- a/html-mode-expansions.el
+++ b/html-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; html-mode-expansions.el --- HTML-specific expansions for expand-region
+;;; html-mode-expansions.el --- HTML-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -36,10 +36,11 @@
(require 'sgml-mode)
(defun er/mark-html-attribute ()
- "Mark html-attribute presumes that point is at the assignment part of
attr=\"value\".
+ "Mark html-attribute.
+Presumes that point is at the assignment part of attr=\"value\".
If point is inside the value-string, the quotes will be marked
first anyway. Does not support html-attributes with spaces
-around the equal sign or unquotes attributes atm."
+around the equal sign or unquoted attributes atm."
(interactive)
(when (or (looking-at "\\(\\s_\\|\\sw\\)*=")
(er/looking-back-exact "="))
@@ -93,10 +94,10 @@ around the equal sign or unquotes attributes atm."
er/mark-inner-tag
er/mark-outer-tag))))
-(er/enable-mode-expansions 'html-mode 'er/add-html-mode-expansions)
-(er/enable-mode-expansions 'rhtml-mode 'er/add-html-mode-expansions)
-(er/enable-mode-expansions 'nxhtml-mode 'er/add-html-mode-expansions)
-(er/enable-mode-expansions 'web-mode 'er/add-html-mode-expansions)
+(er/enable-mode-expansions 'html-mode #'er/add-html-mode-expansions)
+(er/enable-mode-expansions 'rhtml-mode #'er/add-html-mode-expansions)
+(er/enable-mode-expansions 'nxhtml-mode #'er/add-html-mode-expansions)
+(er/enable-mode-expansions 'web-mode #'er/add-html-mode-expansions)
(provide 'html-mode-expansions)
diff --git a/js-mode-expansions.el b/js-mode-expansions.el
index 3f0df19a20..85e20e902d 100644
--- a/js-mode-expansions.el
+++ b/js-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; js-mode-expansions.el --- JS-specific expansions for expand-region
+;;; js-mode-expansions.el --- JS-specific expansions for expand-region -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -36,6 +36,7 @@
;;; Code:
(require 'expand-region-core)
+(require 'er-basic-expansions)
(defun er/mark-js-function ()
"Mark the current JavaScript function."
@@ -72,7 +73,8 @@
(exchange-point-and-mark))
(defun er/mark-js-inner-return ()
- "Mark contents of the current return statement, not including return or
semi-colon"
+` "Mark contents of the current return statement.
+Does not include return or semi-colon."
(interactive)
(condition-case nil
(forward-char 6)
@@ -128,7 +130,8 @@
(exchange-point-and-mark))
(defun er/mark-js-object-property ()
- "Mark js-object-property presumes that point is at the assignment part of
key: value.
+ "Mark js-object-property.
+Presumes that point is at the assignment part of key: value.
If point is inside the value, that will be marked first anyway."
(interactive)
(when (or (looking-at "\"?\\(\\s_\\|\\sw\\| \\)*\":")
@@ -178,9 +181,9 @@ If point is inside the value, that will be marked first
anyway."
er/mark-js-outer-return
er/mark-js-call))))
-(er/enable-mode-expansions 'js-mode 'er/add-js-mode-expansions)
-(er/enable-mode-expansions 'js2-mode 'er/add-js-mode-expansions)
-(er/enable-mode-expansions 'js3-mode 'er/add-js-mode-expansions)
+(er/enable-mode-expansions 'js-mode #'er/add-js-mode-expansions)
+(er/enable-mode-expansions 'js2-mode #'er/add-js-mode-expansions)
+(er/enable-mode-expansions 'js3-mode #'er/add-js-mode-expansions)
(provide 'js-mode-expansions)
diff --git a/js2-mode-expansions.el b/js2-mode-expansions.el
index 71dc8cc721..122d65d012 100644
--- a/js2-mode-expansions.el
+++ b/js2-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; js2-mode-expansions.el --- Additional expansions for js2-mode
+;;; js2-mode-expansions.el --- Additional expansions for js2-mode -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -52,7 +52,7 @@
er/try-expand-list
'(js2-mark-parent-statement))))
-(er/enable-mode-expansions 'js2-mode 'er/add-js2-mode-expansions)
+(er/enable-mode-expansions 'js2-mode #'er/add-js2-mode-expansions)
(provide 'js2-mode-expansions)
diff --git a/jsp-expansions.el b/jsp-expansions.el
index 40a823ed94..23309d36d4 100644
--- a/jsp-expansions.el
+++ b/jsp-expansions.el
@@ -1,6 +1,6 @@
-;;; jsp-expansions.el --- JSP-specific expansions for expand-region
+;;; jsp-expansions.el --- JSP-specific expansions for expand-region -*-
lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen <magnars@gmail.com>
;; Keywords: marking region
@@ -57,7 +57,7 @@ If point is inside the brackets, they will be marked first
anyway."
er/try-expand-list
'(er/mark-jstl-escape))))
-(er/enable-mode-expansions 'html-mode 'er/add-jsp-expansions)
+(er/enable-mode-expansions 'html-mode #'er/add-jsp-expansions)
(provide 'jsp-expansions)
diff --git a/latex-mode-expansions.el b/latex-mode-expansions.el
index 487bca4b51..48cc713082 100644
--- a/latex-mode-expansions.el
+++ b/latex-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; latex-mode-expansions.el --- LaTeX-specific expansions for expand-region
+;;; latex-mode-expansions.el --- LaTeX-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Ivan Andrus
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -96,7 +96,7 @@ Skips past [] and {} arguments to the environment."
er/mark-LaTeX-math))))
(let ((latex-mode-hook LaTeX-mode-hook))
- (er/enable-mode-expansions 'latex-mode 'er/add-latex-mode-expansions)
+ (er/enable-mode-expansions 'latex-mode #'er/add-latex-mode-expansions)
(setq LaTeX-mode-hook latex-mode-hook))
(provide 'latex-mode-expansions)
diff --git a/nxml-mode-expansions.el b/nxml-mode-expansions.el
index cd3856cdbb..7fe2deedd3 100644
--- a/nxml-mode-expansions.el
+++ b/nxml-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; nxml-mode-expansions.el --- Nxml-specific expansions for expand-region
+;;; nxml-mode-expansions.el --- Nxml-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Ivan Andrus
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -118,7 +118,7 @@ point is in, or otherwise nil"
(remove 'er/mark-symbol-with-prefix
(remove 'er/mark-symbol er/try-expand-list))))))
-(er/enable-mode-expansions 'nxml-mode 'er/add-nxml-mode-expansions)
+(er/enable-mode-expansions 'nxml-mode #'er/add-nxml-mode-expansions)
(provide 'nxml-mode-expansions)
diff --git a/octave-expansions.el b/octave-expansions.el
index eb4456f946..8866d20b8c 100644
--- a/octave-expansions.el
+++ b/octave-expansions.el
@@ -1,6 +1,6 @@
-;;; octave-expansions.el --- octave-mode expansions for expand-region
+;;; octave-expansions.el --- octave-mode expansions for expand-region -*-
lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Mark Hepburn
;; Keywords: marking region
@@ -72,7 +72,7 @@ behaviour of `octave-mark-block' between emacs versions 23 and
(set (make-local-variable 'er/try-expand-list)
(append er/try-expand-list try-expand-list-additions))))
-(er/enable-mode-expansions 'octave-mode 'er/add-octave-expansions)
+(er/enable-mode-expansions 'octave-mode #'er/add-octave-expansions)
(provide 'octave-expansions)
;;; octave-expansions.el ends here
diff --git a/python-el-expansions.el b/python-el-expansions.el
index 56b20b5217..21aaa22bfd 100644
--- a/python-el-expansions.el
+++ b/python-el-expansions.el
@@ -1,6 +1,6 @@
-;;; python-el-expansions.el --- Python-specific expansions for expand-region
+;;; python-el-expansions.el --- Python-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Authors: Ivan Andrus, Felix Geller, @edmccard
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -85,7 +85,7 @@
(remove 'er/mark-outside-quotes
(append er/try-expand-list
try-expand-list-additions))))))
-(er/enable-mode-expansions 'python-mode 'er/add-python-mode-expansions)
+(er/enable-mode-expansions 'python-mode #'er/add-python-mode-expansions)
(provide 'python-el-expansions)
diff --git a/python-el-fgallina-expansions.el b/python-el-fgallina-expansions.el
index a70f312407..148dccf2a6 100644
--- a/python-el-fgallina-expansions.el
+++ b/python-el-fgallina-expansions.el
@@ -1,6 +1,6 @@
-;;; python-el-fgallina-expansions.el --- fgallina/python.el-specific
expansions for expand-region
+;;; python-el-fgallina-expansions.el --- fgallina/python.el-specific
expansions for expand-region -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Felix Geller
;; Keywords: marking region python
@@ -34,9 +34,9 @@
(require 'expand-region-core)
(if (not (fboundp 'python-syntax-context))
- (defalias 'python-syntax-context 'python-info-ppss-context))
+ (defalias 'python-syntax-context #'python-info-ppss-context))
(if (not (fboundp 'python-indent-offset))
- (defalias 'python-indent-offset 'python-indent))
+ (defalias 'python-indent-offset #'python-indent))
(defvar er--python-string-delimiter
"'\""
@@ -123,7 +123,7 @@ than NEXT-INDENT-LEVEL."
;; No need to go beyond the end of the buffer. Can't use
;; eobp as the loop places the point at the beginning of
;; line, but eob might be at the end of the line.
- (not (= (point-max) (point-at-eol)))
+ (not (= (point-max) (line-end-position)))
;; Proceed if: indentation is too deep
(or (> (current-indentation) block-indentation)
;; Looking at an empty line
@@ -186,7 +186,7 @@ Command that wraps `er/mark-python-block'."
(remove 'er/mark-outside-quotes
(append er/try-expand-list
try-expand-list-additions))))))
-(er/enable-mode-expansions 'python-mode 'er/add-python-mode-expansions)
+(er/enable-mode-expansions 'python-mode #'er/add-python-mode-expansions)
(provide 'python-el-fgallina-expansions)
diff --git a/python-mode-expansions.el b/python-mode-expansions.el
index 075d3a2e8e..690fe9b0b0 100644
--- a/python-mode-expansions.el
+++ b/python-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; python-mode-expansions.el --- python-mode-specific expansions for
expand-region
+;;; python-mode-expansions.el --- python-mode-specific expansions for
expand-region -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Felix Geller
;; Based on python-mode-expansions by: Ivan Andrus
@@ -43,7 +43,7 @@
(defvar er--python-string-delimiter "'\"")
-(defalias 'py-goto-beyond-clause 'py-end-of-clause-bol)
+(defalias 'py-goto-beyond-clause #'py-end-of-clause-bol)
(declare-function py-in-string-p "python-mode")
(declare-function py-beginning-of-block "python-mode")
@@ -140,7 +140,7 @@ line and selecting the surrounding block."
(remove 'er/mark-outside-quotes
(append er/try-expand-list
try-expand-list-additions))))))
-(er/enable-mode-expansions 'python-mode 'er/add-python-mode-expansions)
+(er/enable-mode-expansions 'python-mode #'er/add-python-mode-expansions)
(provide 'python-mode-expansions)
diff --git a/ruby-mode-expansions.el b/ruby-mode-expansions.el
index 3a66c2e025..03f38f096b 100644
--- a/ruby-mode-expansions.el
+++ b/ruby-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; ruby-mode-expansions.el --- ruby-specific expansions for expand-region
+;;; ruby-mode-expansions.el --- ruby-specific expansions for expand-region
-*- lexical-binding: t; -*-
-;; Copyright (C) 2011-2020 Free Software Foundation, Inc
+;; Copyright (C) 2011-2023 Free Software Foundation, Inc
;; Author: Matt Briggs
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -36,8 +36,9 @@
;;
;;; Code:
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
(require 'expand-region-core)
+(require 'er-basic-expansions)
(require 'ruby-mode)
(defvar er/ruby-block-end-re
@@ -56,7 +57,7 @@ This moves point to the next line to include the end of the
block"
(interactive "p")
;; Workaround for `ruby-end-of-block' in Emacs 23.
(when (re-search-forward (concat "\\<\\(" ruby-block-beg-re "\\)\\>")
- (point-at-eol) t)
+ (line-end-position) t)
(goto-char (match-beginning 0)))
(ruby-end-of-block (or arg 1))
(er/ruby-skip-past-block-end))
@@ -84,21 +85,20 @@ This moves point to the next line to include the end of the
block"
(ruby-beginning-of-block)
;; "Block beginning" is often not at indentation in Emacs
24.
(< (er/point-at-indentation) orig-point))
- (loop do
- (ruby-beginning-of-block)
- (setq progress-beg (point))
- (when (= (point) (point-min))
- (return))
- (ruby-end-of-block)
- (setq progress-end (if (looking-at-p er/ruby-block-end-re)
- (point-at-bol 0)
- (point-at-bol 1)))
- (goto-char progress-beg)
- (when (> progress-end orig-point)
- (return))))))
-
-;;; This command isn't used here explicitly, but it's symmetrical with
-;;; `er/ruby-backward-up', and nifty for interactive use.
+ (cl-loop
+ (ruby-beginning-of-block)
+ (setq progress-beg (point))
+ (when (= (point) (point-min))
+ (cl-return))
+ (ruby-end-of-block)
+ (setq progress-end (line-beginning-position
+ (if (looking-at-p er/ruby-block-end-re) 0 1)))
+ (goto-char progress-beg)
+ (when (> progress-end orig-point)
+ (cl-return))))))
+
+;; This command isn't used here explicitly, but it's symmetrical with
+;; `er/ruby-backward-up', and nifty for interactive use.
(defun er/ruby-forward-up ()
"a la `paredit-forward-up'"
(interactive)
@@ -110,13 +110,12 @@ This moves point to the next line to include the end of
the block"
(setq pos (or pos (point)))
(save-excursion
(goto-char pos)
- (let (beg end)
- (cons (progn
- (er/ruby-backward-up)
- (er/point-at-indentation))
- (progn
- (er/ruby-end-of-block)
- (point))))))
+ (cons (progn
+ (er/ruby-backward-up)
+ (er/point-at-indentation))
+ (progn
+ (er/ruby-end-of-block)
+ (point)))))
(defun er/mark-ruby-block-up-1 ()
(er/ruby-backward-up)
@@ -137,12 +136,12 @@ This moves point to the next line to include the end of
the block"
(forward-line 0)
(back-to-indentation)
(cond ((looking-at-p er/ruby-block-end-re)
- (point-at-bol 0))
+ (line-beginning-position 0))
((re-search-forward
(concat "\\<\\(" ruby-block-beg-re "\\)\\>")
- (point-at-eol)
+ (line-end-position)
t)
- (point-at-bol 2))) )
+ (line-beginning-position 2))) )
(point)))
(prev-block-info (er/get-ruby-block prev-block-point))
(prev-block-beg (car prev-block-info))
@@ -201,5 +200,5 @@ be marked first anyway."
er/mark-ruby-block-up
er/mark-ruby-heredoc)))))
-(er/enable-mode-expansions 'ruby-mode 'er/add-ruby-mode-expansions)
+(er/enable-mode-expansions 'ruby-mode #'er/add-ruby-mode-expansions)
(provide 'ruby-mode-expansions)
diff --git a/sml-mode-expansions.el b/sml-mode-expansions.el
index 296a31857f..1af2fc2eba 100644
--- a/sml-mode-expansions.el
+++ b/sml-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; sml-mode-expansions.el --- Expansions for expand-region to be used in
sml-mode
+;;; sml-mode-expansions.el --- Expansions for expand-region to be used in
sml-mode -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Alexis Gallagher
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -57,7 +57,7 @@
er/sml-mark-keyword-prefixed-expression
mark-sexp))))
-(er/enable-mode-expansions 'sml-mode 'er/add-sml-mode-expansions)
+(er/enable-mode-expansions 'sml-mode #'er/add-sml-mode-expansions)
(provide 'sml-mode-expansions)
diff --git a/subword-mode-expansions.el b/subword-mode-expansions.el
index f28895b9a4..2e6600251c 100644
--- a/subword-mode-expansions.el
+++ b/subword-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; subword-mode-expansions.el --- Expansions for subword-mode to be used for
CamelCase
+;;; subword-mode-expansions.el --- Expansions for subword-mode to be used for
CamelCase -*- lexical-binding: t; -*-
-;; Copyright (C) 2014-2020 Free Software Foundation, Inc
+;; Copyright (C) 2014-2023 Free Software Foundation, Inc
;; Author: Lefteris Karapetsas
;; Keywords: marking region
diff --git a/text-mode-expansions.el b/text-mode-expansions.el
index c26d7d4984..628443bb57 100644
--- a/text-mode-expansions.el
+++ b/text-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; text-mode-expansions.el --- Expansions for expand-region to be used in text
+;;; text-mode-expansions.el --- Expansions for expand-region to be used in
text -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Ivan Andrus
;; Based on js-mode-expansions by: Magnar Sveen <magnars@gmail.com>
@@ -58,7 +58,7 @@ text-mode-expansions don't work well in `html-mode'."
er/mark-text-paragraph
mark-page)))))
-(er/enable-mode-expansions 'text-mode 'er/add-text-mode-expansions)
+(er/enable-mode-expansions 'text-mode #'er/add-text-mode-expansions)
(provide 'text-mode-expansions)
diff --git a/the-org-mode-expansions.el b/the-org-mode-expansions.el
index c055486859..02ae56c292 100644
--- a/the-org-mode-expansions.el
+++ b/the-org-mode-expansions.el
@@ -1,6 +1,6 @@
-;;; the-org-mode-expansions.el --- Expansions for expand-region to be used in
org-mode
+;;; the-org-mode-expansions.el --- Expansions for expand-region to be used in
org-mode -*- lexical-binding: t; -*-
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Author: Magnar Sveen
;; Based on text-mode-expansions by: Ivan Andrus
@@ -32,6 +32,7 @@
;;; Code:
(require 'expand-region-core)
+(require 'er-basic-expansions)
(require 'org-macs)
(declare-function org-up-element "org")
@@ -113,6 +114,6 @@
(set (make-local-variable 'er/save-mode-excursion)
#'er/save-org-mode-excursion))
-(er/enable-mode-expansions 'org-mode 'er/add-org-mode-expansions)
+(er/enable-mode-expansions 'org-mode #'er/add-org-mode-expansions)
(provide 'the-org-mode-expansions)
diff --git a/web-mode-expansions.el b/web-mode-expansions.el
index 0c44094c23..8fad2efb36 100644
--- a/web-mode-expansions.el
+++ b/web-mode-expansions.el
@@ -1,7 +1,7 @@
-;;; web-mode-expansions.el --- Thin layer for adapting fxbois's
web-mode-mark-and-expand function
+;;; web-mode-expansions.el --- Thin layer for adapting fxbois's
web-mode-mark-and-expand function -*- lexical-binding: t; -*-
;;; to expand-region
-;; Copyright (C) 2012-2020 Free Software Foundation, Inc
+;; Copyright (C) 2012-2023 Free Software Foundation, Inc
;; Authors: Rotem Yaari
;; Based on, and makes use of web-mode.el by fxbois
@@ -27,6 +27,6 @@
(set (make-local-variable 'er/try-expand-list)
(cons 'web-mode-mark-and-expand er/try-expand-list)))
-(er/enable-mode-expansions 'web-mode 'er/add-web-mode-expansions)
+(er/enable-mode-expansions 'web-mode #'er/add-web-mode-expansions)
(provide 'web-mode-expansions)
diff --git a/yaml-mode-expansions.el b/yaml-mode-expansions.el
new file mode 100644
index 0000000000..7bc4aeb76e
--- /dev/null
+++ b/yaml-mode-expansions.el
@@ -0,0 +1,194 @@
+;;; yaml-mode-expansions.el --- expansions for yaml mode -*- lexical-binding:
t; -*-
+
+;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
+
+;; Author: Aaron Gonzales
+;; Keywords: marking region yaml YAML expand
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; - Additions implemented here:
+;; - er/mark-yaml-key-value
+;; - er/mark-yaml-list-item
+;; - er/mark-yaml-block
+;; - er/mark-yaml-outer-block
+;; - er/mark-yaml-inner-block
+
+
+;;; Code:
+
+(require 'expand-region-core)
+
+(defconst yaml-indent 2)
+
+(unless (fboundp 'yaml-indent-offset)
+ (defalias 'yaml-indent-offset #'yaml-indent))
+
+(defvar er--yaml-key-value-regex
+ (rx (one-or-more
+ (any "0-9A-Za-z"))
+ ":"
+ (zero-or-more " ")
+ (one-or-more
+ (any "0-9A-Za-z" " '_-"))))
+
+(defvar er--yaml-list-item-regex
+ (rx (seq "- "
+ (one-or-more
+ (any "0-9A-Za-z" "\"':=_-")))))
+
+(defvar er--yaml-block-regex
+ (rx (seq (zero-or-more
+ (any " -"))
+ (one-or-more
+ (any "0-9A-Za-z" " '_-"))
+ ":\n")))
+
+(defun er--get-regex-indentation-level (regex)
+ "Return the indentation level of the code with respect to the REGEX passed."
+ (when (looking-at regex)
+ ;; Block start means that the next level is deeper.
+ (+ (current-indentation) yaml-indent-offset) ;FIXME: Unused?
+ ;; Assuming we're inside the block that we want to mark
+ (current-indentation)))
+
+(defun er/mark-yaml-line-base (regex)
+ "Mark line of yaml file based on simple REGEX."
+ (back-to-indentation)
+ (when (looking-at regex)
+ (set-mark (line-end-position))))
+
+(defun er/mark-yaml-block-static-base (regex)
+ "Mark yaml block based on REGEX passed."
+ ;; go bac to indentation so always can get regexp
+ (back-to-indentation)
+ ;; make sure the cursor is set inside the block
+ ;; mark point at this higher code block
+ (set-mark (point))
+ ;; save level of this blocks indentation
+ (let ((block-indentation (current-indentation)))
+ (forward-line 1)
+ (while (and
+ ;; No need to go beyond the end of the buffer. Can't use
+ ;; eobp as the loop places the point at the beginning of
+ ;; line, but eob might be at the end of the line.
+ (not (= (point-max) (line-end-position)))
+ ;; Proceed if: indentation is too deep
+ (or (> (current-indentation) block-indentation)
+ ;; Looking at an empty line
+ (looking-at (rx line-start (* whitespace) line-end))
+ ;; We're not looking at the start of a YAML block
+ ;; and the indent is deeper than the block's indent
+ (and (not (looking-at regex))
+ (> (current-indentation) block-indentation))))
+ (forward-line 1)
+ (back-to-indentation))
+ ;; Find the end of the block by skipping comments backwards
+ (python-util-forward-comment -1)
+ (exchange-point-and-mark))
+ (back-to-indentation))
+
+(defun er/mark-yaml-block-base (regex &optional next-indent-level)
+ "Mark yaml block based on REGEX passed.
+NEXT-INDENT-LEVEL can be used to search outer blocks when necessary."
+ ;; go bac to indentation so always can get regexp
+ (back-to-indentation)
+ ;; make sure the cursor is set inside the block
+ (let ((next-indent-level
+ (or
+ ;; Use the given level
+ next-indent-level
+ ;; used to mark current block
+ (er--get-regex-indentation-level regex))))
+ ;; if true then at start of block and wanna mark itself
+ ;; else were are inside the block already and will mark it)))
+ ;; move up the code unti a parent code block is reached
+ (while (and (>= (current-indentation) next-indent-level)
+ (not (eq (current-indentation) 0)))
+ (re-search-backward regex (point-min) t)
+ (back-to-indentation))
+ ;; mark point at this higher code block
+ (set-mark (point))
+ ;; save level of this blocks indentation
+ (let ((block-indentation (current-indentation)))
+ (forward-line 1)
+ (while (and
+ ;; No need to go beyond the end of the buffer. Can't use
+ ;; eobp as the loop places the point at the beginning of
+ ;; line, but eob might be at the end of the line.
+ (not (= (point-max) (line-end-position)))
+ ;; Proceed if: indentation is too deep
+ (or (> (current-indentation) block-indentation)
+ ;; Looking at an empty line
+ (looking-at (rx line-start (* whitespace) line-end))
+ ;; We're not looking at the start of a YAML block
+ ;; and the indent is deeper than the block's indent
+ (and (not (looking-at regex))
+ (> (current-indentation) block-indentation))))
+ (forward-line 1)
+ (back-to-indentation))
+ ;; Find the end of the block by skipping comments backwards
+ (python-util-forward-comment -1)
+ (exchange-point-and-mark)))
+ (back-to-indentation))
+
+(defun er/mark-yaml-key-value ()
+ "Mark a yaml key-value pair."
+ (interactive)
+ (er/mark-yaml-line-base er--yaml-key-value-regex))
+
+(defun er/mark-yaml-list-item ()
+ "Mark a yaml list item."
+ (interactive)
+ (er/mark-yaml-line-base er--yaml-list-item-regex))
+
+(defun er/mark-yaml-inner-block ()
+ "Mark the yaml contents of the block at point.
+Command that wraps `er/mark-yaml-block-base'."
+ (interactive)
+ (er/mark-yaml-block-base er--yaml-block-regex (current-indentation))
+ (forward-line)
+ (back-to-indentation))
+
+(defun er/mark-yaml-block ()
+ "Mark the yaml block that point is currently at the top of.
+Command that wraps `er/mark-yaml-block-base'."
+ (interactive)
+ (er/mark-yaml-block-static-base er--yaml-block-regex))
+
+(defun er/mark-yaml-outer-block ()
+ "Mark the outer yaml block that surrounds the block around point.
+Command that wraps `er/mark-yaml-block-base'."
+ (interactive)
+ (er/mark-yaml-block-base er--yaml-block-regex (current-indentation)))
+
+(defun er/add-yaml-mode-expansions ()
+ "Add yaml-mode-specific expansions for buffers in yaml-mode."
+ (let ((try-expand-list-additions '(er/mark-symbol
+ er/mark-outside-quotes
+ er/mark-yaml-list-item
+ er/mark-yaml-key-value
+ er/mark-yaml-block
+ er/mark-yaml-outer-block
+ er/mark-yaml-inner-block)))
+ (set (make-local-variable 'expand-region-skip-whitespace) nil)
+ (set (make-local-variable 'er/try-expand-list) try-expand-list-additions)))
+
+(er/enable-mode-expansions 'yaml-mode #'er/add-yaml-mode-expansions)
+
+(provide 'yaml-mode-expansions)
+
+;;; yaml-mode-expansions.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/expand-region 8493232800: Update code for lexical-binding, cl-lib, and advice-add,
Stefan Monnier <=