unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#49999: 27.2; save-mark-and-excursion does not save mark-active
@ 2021-08-11  9:59 Peter Münster
  2021-08-11 12:19 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Münster @ 2021-08-11  9:59 UTC (permalink / raw)
  To: 49999

Hi,

It seems, that save-mark-and-excursion does not restore the mark state.

Here is a test function:

(defun my-test-func ()
  "Test if save-mark-and-excursion is working."
  (interactive)
  (with-current-buffer "test-buf"
    (save-mark-and-excursion
      (goto-char (point-min))
      (add-face-text-property
       (point) (1+ (point)) (list :background "orange")))))

Test case:
- "emacs -Q"
- evaluate my-test-func
- open a new buffer "test-buf"
- type some characters
- mark a region somewhere
- M-x my-test-func

Result: point is restored, but mark-active is nil.

Kind regards, Peter



In GNU Emacs 27.2 (build 1, x86_64-suse-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: openSUSE Leap 15.2

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...

Configured using:
 'configure --disable-build-details --with-pop --without-hesiod
 --with-gameuser=:games --with-kerberos --with-kerberos5
 --with-file-notification=inotify --with-modules --enable-autodepend
 --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
 --datadir=/usr/share --localstatedir=/var --sharedstatedir=/var/lib
 --libexecdir=/usr/lib
 --enable-locallisppath=/usr/share/emacs/27.2/site-lisp:/usr/share/emacs/site-lisp
 --with-x --with-xim --with-sound --with-xpm --with-jpeg --with-tiff
 --with-gif --with-png --with-rsvg --with-dbus --with-xft --without-gpm
 --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 --x-includes=/usr/include --x-libraries=/usr/lib64 --with-libotf
 --with-m17n-flt --with-cairo --with-xwidgets --build=x86_64-suse-linux
 --with-dumping=pdumper 'CFLAGS=-fmessage-length=0 -grecord-gcc-switches
 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables
 -fasynchronous-unwind-tables -fstack-clash-protection -g -D_GNU_SOURCE
 -DGDK_DISABLE_DEPRECATION_WARNINGS -DGLIB_DISABLE_DEPRECATION_WARNINGS
 -pipe -Wno-pointer-sign -Wno-unused-variable -Wno-unused-label
 -fno-optimize-sibling-calls -fno-PIE -DSYSTEM_PURESIZE_EXTRA=55000
 -DSITELOAD_PURESIZE_EXTRA=10000 -DPDMP_BASE='\''"emacs-gtk"'\'''
 LDFLAGS=-Wl,-O2'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS
LIBSYSTEMD JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LC_CTYPE: en_GB.utf8
  value of $LC_MESSAGES: en_GB.utf8
  value of $LC_NUMERIC: POSIX
  value of $XMODIFIERS: @im=local
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
delsel lpr easy-mmode pcase tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core term/tty-colors frame
minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite charscript charprop case-table epa-hook jka-cmpr-hook help
simple abbrev obarray cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting xwidget-internal cairo move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 44541 7328)
 (symbols 48 5999 1)
 (strings 32 15714 1987)
 (string-bytes 1 506059)
 (vectors 16 9402)
 (vector-slots 8 125772 9350)
 (floats 8 20 43)
 (intervals 56 279 0)
 (buffers 1000 13))

-- 
           Peter





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#49999: 27.2; save-mark-and-excursion does not save mark-active
  2021-08-11  9:59 bug#49999: 27.2; save-mark-and-excursion does not save mark-active Peter Münster
@ 2021-08-11 12:19 ` Lars Ingebrigtsen
  2021-08-11 15:46   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-11 12:19 UTC (permalink / raw)
  To: Peter Münster; +Cc: 49999

Peter Münster <pm@a16n.net> writes:

> It seems, that save-mark-and-excursion does not restore the mark state.
>
> Here is a test function:
>
> (defun my-test-func ()
>   "Test if save-mark-and-excursion is working."
>   (interactive)
>   (with-current-buffer "test-buf"
>     (save-mark-and-excursion
>       (goto-char (point-min))
>       (add-face-text-property
>        (point) (1+ (point)) (list :background "orange")))))
>
> Test case:
> - "emacs -Q"
> - evaluate my-test-func
> - open a new buffer "test-buf"
> - type some characters
> - mark a region somewhere
> - M-x my-test-func
>
> Result: point is restored, but mark-active is nil.

I can reproduce this, but I'm not quite sure what's going on.  I tweaked
your function:

(defun my-test-func ()
  "Test if save-mark-and-excursion is working."
  (interactive)
  (save-mark-and-excursion
    (goto-char (point-min))
    (add-face-text-property
     (point) (1+ (point)) (list :background "orange")))
  (message "%s" mark-active))

This messages t -- but evaling mark-active afterwards shows that it's
nil.  So something is deactivating the mark after the command has run,
apparently?  Hm...  this sounds vaguely familiar to me...  Anybody know
what could be going on here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#49999: 27.2; save-mark-and-excursion does not save mark-active
  2021-08-11 12:19 ` Lars Ingebrigtsen
@ 2021-08-11 15:46   ` Lars Ingebrigtsen
  2021-08-13  9:19     ` Peter Münster
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-11 15:46 UTC (permalink / raw)
  To: Peter Münster; +Cc: 49999

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I can reproduce this, but I'm not quite sure what's going on.  I tweaked
> your function:
>
> (defun my-test-func ()
>   "Test if save-mark-and-excursion is working."
>   (interactive)
>   (save-mark-and-excursion
>     (goto-char (point-min))
>     (add-face-text-property
>      (point) (1+ (point)) (list :background "orange")))
>   (message "%s" mark-active))
>
> This messages t -- but evaling mark-active afterwards shows that it's
> nil.  So something is deactivating the mark after the command has run,
> apparently?  Hm...  this sounds vaguely familiar to me...  Anybody know
> what could be going on here?

Oh, right -- it's transient mark mode that does this stuff?  That is, if
you run a command that inserts something in the buffer, then it'll
switch the region off?

So `save-mark-and-excursion' works exactly as it should.  But if you
don't want transient-mark-mode to switch itself off, you have to say
something like:

(defun my-test-func ()
  "Test if save-mark-and-excursion is working."
  (interactive)
  (save-mark-and-excursion
    (goto-char (point-min))
    (with-silent-modifications
      (add-face-text-property
       (point) (1+ (point)) (list :background "orange")))))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#49999: 27.2; save-mark-and-excursion does not save mark-active
  2021-08-11 15:46   ` Lars Ingebrigtsen
@ 2021-08-13  9:19     ` Peter Münster
  2021-08-13 10:30       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Münster @ 2021-08-13  9:19 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 49999


[-- Attachment #1.1: Type: text/plain, Size: 325 bytes --]

On Wed, Aug 11 2021, Lars Ingebrigtsen wrote:

> So `save-mark-and-excursion' works exactly as it should.  But if you
> don't want transient-mark-mode to switch itself off, you have to say
> something like:

Thanks for your explanation. Please find attached a patch, that uses
your solution.

-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Minor-enhancements-for-image-dired.el.patch --]
[-- Type: text/x-patch, Size: 2153 bytes --]

From 8e0d6c4e787ecb56ef8eede83ea5c5d8ed0db5e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Fri, 13 Aug 2021 11:13:43 +0200
Subject: [PATCH] Minor enhancements for image-dired.el

* lisp/image-dired.el (image-dired-thumb-visible-marks): Add the group.
(image-dired-thumb-update-marks): Keep the mark state when changing faces.
---
 lisp/image-dired.el | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 76c7ae91f0..34bf1d02a9 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -465,6 +465,7 @@ This is where you see the cursor."
 If non-nil, apply the `image-dired-thumb-mark' face to marked
 images."
   :type 'boolean
+  :group 'image-dired
   :version "28.1")
 
 (defface image-dired-thumb-mark
@@ -2360,20 +2361,18 @@ non-nil."
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
-  ;; TODO: only called by image-dired-mouse-toggle-mark but there are
-  ;; certainly other places, where it should be called too.
   (when image-dired-thumb-visible-marks
     (with-current-buffer image-dired-thumbnail-buffer
-      (save-excursion
+      (save-mark-and-excursion
         (goto-char (point-min))
         (let ((inhibit-read-only t))
           (while (not (eobp))
-            (if (image-dired-thumb-file-marked-p)
-                (add-face-text-property
-                 (point) (1+ (point))
-                 'image-dired-thumb-mark)
-              (remove-text-properties (point) (1+ (point))
-                                      '(face image-dired-thumb-mark)))
+            (with-silent-modifications
+              (if (image-dired-thumb-file-marked-p)
+                  (add-face-text-property (point) (1+ (point))
+                                          'image-dired-thumb-mark)
+                (remove-text-properties (point) (1+ (point))
+                                        '(face image-dired-thumb-mark))))
             (forward-char)))))))
 
 (defun image-dired-mouse-toggle-mark-1 ()
-- 
2.26.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#49999: 27.2; save-mark-and-excursion does not save mark-active
  2021-08-13  9:19     ` Peter Münster
@ 2021-08-13 10:30       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-13 10:30 UTC (permalink / raw)
  To: Peter Münster; +Cc: 49999

Peter Münster <pm@a16n.net> writes:

> Thanks for your explanation. Please find attached a patch, that uses
> your solution.

Thanks; applied with one change:

> +  :group 'image-dired

We don't normally add :group to defcustoms these days -- the `defgroup'
at the start of the file says what group they belong in.

(I've now removed all the :group things from the defcustoms in the
file.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-13 10:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  9:59 bug#49999: 27.2; save-mark-and-excursion does not save mark-active Peter Münster
2021-08-11 12:19 ` Lars Ingebrigtsen
2021-08-11 15:46   ` Lars Ingebrigtsen
2021-08-13  9:19     ` Peter Münster
2021-08-13 10:30       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).