help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

avoid narrow-to-region (was: Re: replace-regexp)


From: Emanuel Berg
Subject: avoid narrow-to-region (was: Re: replace-regexp)
Date: Sun, 09 May 2021 00:59:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

> I recommend avoiding the use of narrowing as much as
> possible since it can have other undesirable effects (e.g.
> it changes the result of things like `syntax-ppss`).

I checked my Elisp for `narrow-to-region' and found just one
use, namely

(defun sort-lines-random (beg end)
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr nil
                 #'forward-line
                 #'end-of-line
                 nil nil
                 (lambda (_ __) (zerop (random 2)) )))))
(defalias 'r #'sort-lines-random)

;; test here:
;; aaa
;; ccc
;; ddd
;; bbb

If one were to remove it, how would one specify the end of
the operation?

https://dataswamp.org/~incal/emacs-init/sort-incal.el

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]