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

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

bug#22819: 25.0.91; Don't try to indent region if the buffer is read-onl


From: Kaushal Modi
Subject: bug#22819: 25.0.91; Don't try to indent region if the buffer is read-only
Date: Mon, 07 Aug 2017 18:02:21 +0000

On Mon, Aug 7, 2017 at 1:53 PM Noam Postavsky <npostavs@users.sourceforge.net> wrote:

hmm, I can't reproduce here, but is it possible you have bound C-M-\
to some other command which calls indent-region non-interactively?

Thanks for verifying. Of course it was my config..

This deviates from this bug report.. but I am open to suggestions on how I could retain the * property of the interactive form while setting the region boundaries as I do in the below advice.

I confirm that your suggestion also works fine if I remove the below advice from my config.

=====
(defvar modi/region-or-whole-fns '(indent-region
                                   eval-region)
  "List of functions to act on the whole buffer if no region is selected.")

(defun modi/advice-region-or-whole (orig-fun &rest args)
  "Advice function that applies ORIG-FUN to the whole buffer if no region is
selected.
http://thread.gmane.org/gmane.emacs.help/109025/focus=109102 "
  ;; Required to override the "r" argument of `interactive' in functions like
  ;; `indent-region' so that they can be called without an active region.
  (interactive (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (list (point-min) (point-max))))
  ;; (message "Args: %S R: %S I: %S"
  ;;          args (use-region-p) (called-interactively-p 'interactive))
  (prog1 ; Return value of the advising fn needs to be the same as ORIG-FUN
      (apply orig-fun args)
    (when (and (called-interactively-p 'interactive)
               (not (use-region-p)))
      (message "Executed %s on the whole buffer."
               (propertize (symbol-name this-command)
                           'face 'font-lock-function-name-face)))))

(dolist (fn modi/region-or-whole-fns)
  (advice-add fn :around #'modi/advice-region-or-whole)
  ;; (advice-remove fn #'modi/advice-region-or-whole)
  ) 
=====
--

Kaushal Modi


reply via email to

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