all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: master fe7c015b20: Support XFCE in wallpaper.el
       [not found] ` <20220916204419.B124FC00872@vcs2.savannah.gnu.org>
@ 2022-09-17  2:00   ` Po Lu
  2022-09-17 18:03     ` Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-17  2:00 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Kangas

Stefan Kangas <stefankangas@gmail.com> writes:

> +    ("xfconf-query" "-c" "xfce4-desktop" "-p"
> +     "/backdrop/screen0/monitoreDP/workspace0/last-image" "-s" "%f")

Judging by the command, this assumes that:

 - the screen number is 0
 - the monitor on which the backdrop will be changed is named "eDP"
 - the workspace is 0

These assumptions do not hold true on machines where XFCE is running on
a different screen, on a monitor named something other than "eDP", or
when the user has enabled more than 1 workspace.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-17  2:00   ` master fe7c015b20: Support XFCE in wallpaper.el Po Lu
@ 2022-09-17 18:03     ` Stefan Kangas
  2022-09-18  1:18       ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-17 18:03 UTC (permalink / raw)
  To: Po Lu, emacs-devel; +Cc: Thierry Volpiatto

Po Lu <luangruo@yahoo.com> writes:

> Stefan Kangas <stefankangas@gmail.com> writes:
>
>> +    ("xfconf-query" "-c" "xfce4-desktop" "-p"
>> +     "/backdrop/screen0/monitoreDP/workspace0/last-image" "-s" "%f")
>
> Judging by the command, this assumes that:
>
>  - the screen number is 0
>  - the monitor on which the backdrop will be changed is named "eDP"
>  - the workspace is 0

Is "eDP" the most common and/or default name?

Not sure what to do about the screen number or workspaces.  Is there any
way to find out this information with a simple command?

> These assumptions do not hold true on machines where XFCE is running on
> a different screen, on a monitor named something other than "eDP", or
> when the user has enabled more than 1 workspace.

Suggestions for how to improve on this are welcome.

From searching online, the way to find out the above information on XFCE
seems to be a hassle:

https://unix.stackexchange.com/questions/596070/how-to-change-wallpaper-on-xfce-from-terminal

I have no idea why they need make such a basic operation that hard.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-17 18:03     ` Stefan Kangas
@ 2022-09-18  1:18       ` Po Lu
  2022-09-18  2:13         ` Po Lu
                           ` (2 more replies)
  0 siblings, 3 replies; 61+ messages in thread
From: Po Lu @ 2022-09-18  1:18 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: emacs-devel, Thierry Volpiatto

Stefan Kangas <stefankangas@gmail.com> writes:

> Po Lu <luangruo@yahoo.com> writes:
>
>> Stefan Kangas <stefankangas@gmail.com> writes:
>>
>>> +    ("xfconf-query" "-c" "xfce4-desktop" "-p"
>>> +     "/backdrop/screen0/monitoreDP/workspace0/last-image" "-s" "%f")
>>
>> Judging by the command, this assumes that:
>>
>>  - the screen number is 0
>>  - the monitor on which the backdrop will be changed is named "eDP"
>>  - the workspace is 0

> Is "eDP" the most common and/or default name?

No, it's the name used for the embedded DisplayPort internal panel on
laptops.  Some laptops use LVDS instead, and the name is thus "LVDS".

> Not sure what to do about the screen number or workspaces.  Is there any
> way to find out this information with a simple command?

The screen number should be the following part of the `display' frame
parameter:

  1.1.1.1:0.5
            ^ screen number is 5

if there is no period after the separator, then the screen number is 0.

The currently active workspace can be obtained like so:

  (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)

if it fails by returning NULL, then you should fall back to:

  (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)

and failing that, 0.

The monitor name should also be easy to extract with
display-monitor-attributes-list, but if the source is anything other
than "XRandr", "XRandr 1.5" or "Gdk", you should fall back to using "0".



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18  1:18       ` Po Lu
@ 2022-09-18  2:13         ` Po Lu
  2022-09-18  4:48         ` Thierry Volpiatto
  2022-09-26 19:42         ` Stefan Kangas
  2 siblings, 0 replies; 61+ messages in thread
From: Po Lu @ 2022-09-18  2:13 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: emacs-devel, Thierry Volpiatto

Po Lu <luangruo@yahoo.com> writes:

> if it fails by returning NULL, then you should fall back to:
                           ^^^^

nil, of course, sorry.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18  1:18       ` Po Lu
  2022-09-18  2:13         ` Po Lu
@ 2022-09-18  4:48         ` Thierry Volpiatto
  2022-09-18  5:15           ` Po Lu
  2022-09-26 19:42         ` Stefan Kangas
  2 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-18  4:48 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> The currently active workspace can be obtained like so:
>
>   (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)
>
> if it fails by returning NULL, then you should fall back to:
>
>   (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)
>
> and failing that, 0.

Here the command fails if you specify the workspace, it works only with
"worspace0".

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18  4:48         ` Thierry Volpiatto
@ 2022-09-18  5:15           ` Po Lu
  2022-09-18 14:44             ` Thierry Volpiatto
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-18  5:15 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Here the command fails if you specify the workspace, it works only with
> "worspace0".

But that's because you only have workspace 1 displayed, right?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18  5:15           ` Po Lu
@ 2022-09-18 14:44             ` Thierry Volpiatto
  2022-09-19  4:49               ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-18 14:44 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Here the command fails if you specify the workspace, it works only with
>> "worspace0".
>
> But that's because you only have workspace 1 displayed, right?

No, if emacs is on workspace0 and I use:
"/backdrop/screen0/monitoreDP/workspace0/last-image"
wallpaper is modified as expected. 

Then if emacs is on workspace2 and I use:
"/backdrop/screen0/monitoreDP/workspace2/last-image"
Command exit with 0 status but wallpaper is not modified, but if I use:
"/backdrop/screen0/monitoreDP/workspace0/last-image" again (always from
workspace2), wallpaper is modified as expected.

I can verify this with this command which monitor the desktop change:

    xfconf-query -c xfce4-desktop -m

    => Commencer à surveiller le canal « xfce4-desktop » :

then I go to workspace4, modify wallpaper with mouse and the usual xfce
interface for this, go back in workspace1 an look at output:
I have now:

    Commencer à surveiller le canal « xfce4-desktop » :

    définir: /backdrop/screen0/monitoreDP/workspace0/last-image

unfortunately this command is interactive :-(

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18 14:44             ` Thierry Volpiatto
@ 2022-09-19  4:49               ` Po Lu
  2022-09-19  6:06                 ` Thierry Volpiatto
  2022-09-19  7:23                 ` Thierry Volpiatto
  0 siblings, 2 replies; 61+ messages in thread
From: Po Lu @ 2022-09-19  4:49 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Po Lu <luangruo@yahoo.com> writes:
>
>> Thierry Volpiatto <thievol@posteo.net> writes:
>>
>>> Here the command fails if you specify the workspace, it works only with
>>> "worspace0".
>>
>> But that's because you only have workspace 1 displayed, right?
>
> No, if emacs is on workspace0 and I use:
> "/backdrop/screen0/monitoreDP/workspace0/last-image"
> wallpaper is modified as expected. 
>
> Then if emacs is on workspace2 and I use:
> "/backdrop/screen0/monitoreDP/workspace2/last-image"
> Command exit with 0 status but wallpaper is not modified, but if I use:
> "/backdrop/screen0/monitoreDP/workspace0/last-image" again (always from
> workspace2), wallpaper is modified as expected.
>
> I can verify this with this command which monitor the desktop change:
>
>     xfconf-query -c xfce4-desktop -m
>
>     => Commencer à surveiller le canal « xfce4-desktop » :
>
> then I go to workspace4, modify wallpaper with mouse and the usual xfce
> interface for this, go back in workspace1 an look at output:
> I have now:
>
>     Commencer à surveiller le canal « xfce4-desktop » :
>
>     définir: /backdrop/screen0/monitoreDP/workspace0/last-image
>
> unfortunately this command is interactive :-(

But here is how Thunar, the XFCE file manager, sets the backdrop:

          image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/last-image", screen_nr, monitor_name, workspace);
          image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/image-style", screen_nr, monitor_name, workspace);
 
where `workspace' is:

  GdkWindow *root;
  gulong     bytes_after_ret = 0;
  gulong     nitems_ret = 0;
  guint     *prop_ret = NULL;
  Atom       _NET_CURRENT_DESKTOP;
  Atom       _WIN_WORKSPACE;
  Atom       type_ret = None;
  gint       format_ret;
  gint       ws_num = 0;

  gdk_x11_display_error_trap_push (gdk_display_get_default ());

  root = gdk_screen_get_root_window (screen);

  /* determine the X atom values */
  _NET_CURRENT_DESKTOP = XInternAtom (GDK_WINDOW_XDISPLAY (root), "_NET_CURRENT_DESKTOP", False);
  _WIN_WORKSPACE = XInternAtom (GDK_WINDOW_XDISPLAY (root), "_WIN_WORKSPACE", False);

  if (XGetWindowProperty (GDK_WINDOW_XDISPLAY (root),
                          gdk_x11_get_default_root_xwindow(),
                          _NET_CURRENT_DESKTOP, 0, 32, False, XA_CARDINAL,
                          &type_ret, &format_ret, &nitems_ret, &bytes_after_ret,
                          (gpointer) &prop_ret) != Success)
    {
      if (XGetWindowProperty (GDK_WINDOW_XDISPLAY (root),
                              gdk_x11_get_default_root_xwindow(),
                              _WIN_WORKSPACE, 0, 32, False, XA_CARDINAL,
                              &type_ret, &format_ret, &nitems_ret, &bytes_after_ret,
                              (gpointer) &prop_ret) != Success)
        {
          if (G_UNLIKELY (prop_ret != NULL))
            {
              XFree (prop_ret);
              prop_ret = NULL;
            }
        }
    }

  if (G_LIKELY (prop_ret != NULL))
    {
      if (G_LIKELY (type_ret != None && format_ret != 0))
        ws_num = *prop_ret;
      XFree (prop_ret);
    }

  gdk_x11_display_error_trap_pop_ignored (gdk_display_get_default ());

  return ws_num;



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  4:49               ` Po Lu
@ 2022-09-19  6:06                 ` Thierry Volpiatto
  2022-09-19  7:24                   ` Po Lu
  2022-09-19  7:23                 ` Thierry Volpiatto
  1 sibling, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-19  6:06 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 4075 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Po Lu <luangruo@yahoo.com> writes:
>>
>>> Thierry Volpiatto <thievol@posteo.net> writes:
>>>
>>>> Here the command fails if you specify the workspace, it works only with
>>>> "worspace0".
>>>
>>> But that's because you only have workspace 1 displayed, right?
>>
>> No, if emacs is on workspace0 and I use:
>> "/backdrop/screen0/monitoreDP/workspace0/last-image"
>> wallpaper is modified as expected. 
>>
>> Then if emacs is on workspace2 and I use:
>> "/backdrop/screen0/monitoreDP/workspace2/last-image"
>> Command exit with 0 status but wallpaper is not modified, but if I use:
>> "/backdrop/screen0/monitoreDP/workspace0/last-image" again (always from
>> workspace2), wallpaper is modified as expected.
>>
>> I can verify this with this command which monitor the desktop change:
>>
>>     xfconf-query -c xfce4-desktop -m
>>
>>     => Commencer à surveiller le canal « xfce4-desktop » :
>>
>> then I go to workspace4, modify wallpaper with mouse and the usual xfce
>> interface for this, go back in workspace1 an look at output:
>> I have now:
>>
>>     Commencer à surveiller le canal « xfce4-desktop » :
>>
>>     définir: /backdrop/screen0/monitoreDP/workspace0/last-image
>>
>> unfortunately this command is interactive :-(
>
> But here is how Thunar, the XFCE file manager, sets the backdrop:
>
>           image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/last-image", screen_nr, monitor_name, workspace);
>           image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/image-style", screen_nr, monitor_name, workspace);

Yes, sure it is working from thunar. But here from emacs with
it specified, the command output with 0 but the background is not
changed unless I hardcode workspace to 0. 

Here the function used with its Edebug
output:

(defun tv/change-xfce-background (file)
  (let* ((screen  (frame-parameter (selected-frame) 'display))
         (monitor (assoc-default 'name (car (display-monitor-attributes-list))))
         (desktop (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t))
         (prop    (format "/backdrop/screen%s/monitor%s/workspace%s/last-image"
                          (substring screen (1- (length screen)))
                          monitor
                          desktop
                          )))
    (if (= (apply #'call-process "xfconf-query" nil nil nil
                  `("-c" "xfce4-desktop" "-p" ,prop "-s" ,file))
           0)
        (message "Background changed successfully to %s" (helm-basename file))
      (message "Failed to change background"))))

Edebug: tv/change-xfce-background
tv/change-xfce-background

Result: #<frame *scratch* - GNU Emacs at IPad-S340 0x55d297d580f8>

Result: ":0.0"

Result: (((name . "eDP") (geometry 0 0 1920 1080) (workarea 0 0 1920 1080) (mm-size 309 174) (frames #<frame *scratch* - GNU Emacs at IPad-S340 0x55d297d580f8>) (source . "XRandr")))

Result: ((name . "eDP") (geometry 0 0 1920 1080) (workarea 0 0 1920 1080) (mm-size 309 174) (frames #<frame *scratch* - GNU Emacs at IPad-S340 0x55d297d580f8>) (source . "XRandr"))

Result: "eDP"

Result: 2 (#o2, #x2, ?\C-b)

Result: ":0.0"

Result: ":0.0"

Result: 4 (#o4, #x4, ?\C-d)

Result: 3 (#o3, #x3, ?\C-c)

Result: "0"

Result: "eDP"

Result: 2 (#o2, #x2, ?\C-b)

Result: "/backdrop/screen0/monitoreDP/workspace2/last-image"

Result: call-process

Result: "/backdrop/screen0/monitoreDP/workspace2/last-image"

Result: "/home/thierry/backgrounds/Cyclosys.jpg"

Result: ("-c" "xfce4-desktop" "-p" "/backdrop/screen0/monitoreDP/workspace2/last-image" "-s" "/home/thierry/backgrounds/Cyclosys.jpg")

Result: 0 (#o0, #x0, ?\C-@)

Result: t

Result: "/home/thierry/backgrounds/Cyclosys.jpg"

Result: "Cyclosys.jpg"

Background changed successfully to Cyclosys.jpg
Result: "Background changed successfully to Cyclosys.jpg"


-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  4:49               ` Po Lu
  2022-09-19  6:06                 ` Thierry Volpiatto
@ 2022-09-19  7:23                 ` Thierry Volpiatto
  1 sibling, 0 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-19  7:23 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Po Lu <luangruo@yahoo.com> writes:
>>
>>> Thierry Volpiatto <thievol@posteo.net> writes:
>>>
>>>> Here the command fails if you specify the workspace, it works only with
>>>> "worspace0".
>>>
>>> But that's because you only have workspace 1 displayed, right?
>>
>> No, if emacs is on workspace0 and I use:
>> "/backdrop/screen0/monitoreDP/workspace0/last-image"
>> wallpaper is modified as expected. 
>>
>> Then if emacs is on workspace2 and I use:
>> "/backdrop/screen0/monitoreDP/workspace2/last-image"
>> Command exit with 0 status but wallpaper is not modified, but if I use:
>> "/backdrop/screen0/monitoreDP/workspace0/last-image" again (always from
>> workspace2), wallpaper is modified as expected.
>>
>> I can verify this with this command which monitor the desktop change:
>>
>>     xfconf-query -c xfce4-desktop -m
>>
>>     => Commencer à surveiller le canal « xfce4-desktop » :
>>
>> then I go to workspace4, modify wallpaper with mouse and the usual xfce
>> interface for this, go back in workspace1 an look at output:
>> I have now:
>>
>>     Commencer à surveiller le canal « xfce4-desktop » :
>>
>>     définir: /backdrop/screen0/monitoreDP/workspace0/last-image
>>
>> unfortunately this command is interactive :-(
>
> But here is how Thunar, the XFCE file manager, sets the backdrop:
>
>           image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/last-image", screen_nr, monitor_name, workspace);
>           image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%s/workspace%d/image-style", screen_nr, monitor_name, workspace);
>  
> where `workspace' is:
>
>   GdkWindow *root;
>   gulong     bytes_after_ret = 0;
>   gulong     nitems_ret = 0;
>   guint     *prop_ret = NULL;
>   Atom       _NET_CURRENT_DESKTOP;
>   Atom       _WIN_WORKSPACE;
>   Atom       type_ret = None;
>   gint       format_ret;
>   gint       ws_num = 0;


My command starts working with workspace specified when I use an async
process (start-process) instead of call-process, so with wallpaper-set it should work as
expected.
However the functions to extract infos about screen, monitor and
workspace are working only when (display-graphic-p) is non nil.

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  6:06                 ` Thierry Volpiatto
@ 2022-09-19  7:24                   ` Po Lu
  2022-09-19  8:40                     ` Thierry Volpiatto
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-19  7:24 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Yes, sure it is working from thunar. But here from emacs with
> it specified, the command output with 0 but the background is not
> changed unless I hardcode workspace to 0. 

Could you show all of the XFCE settings under /backdrop?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  7:24                   ` Po Lu
@ 2022-09-19  8:40                     ` Thierry Volpiatto
  2022-09-19  8:52                       ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-19  8:40 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Yes, sure it is working from thunar. But here from emacs with
>> it specified, the command output with 0 but the background is not
>> changed unless I hardcode workspace to 0. 
>
> Could you show all of the XFCE settings under /backdrop?

Don't know where I can get that (/backdrop is not a directory).
Do you mean ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml ?

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  8:40                     ` Thierry Volpiatto
@ 2022-09-19  8:52                       ` Po Lu
  2022-09-19 17:46                         ` Thierry Volpiatto
  2022-09-19 18:05                         ` Thierry Volpiatto
  0 siblings, 2 replies; 61+ messages in thread
From: Po Lu @ 2022-09-19  8:52 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Don't know where I can get that (/backdrop is not a directory).

I meant with the `xfconf-query' program, sorry:

  xfconf-query --list --recursive --channel xfce4-desktop --property /backdrop



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  8:52                       ` Po Lu
@ 2022-09-19 17:46                         ` Thierry Volpiatto
  2022-09-19 18:05                         ` Thierry Volpiatto
  1 sibling, 0 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-19 17:46 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2790 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Don't know where I can get that (/backdrop is not a directory).
>
> I meant with the `xfconf-query' program, sorry:

Ok.

>   xfconf-query --list --recursive --channel xfce4-desktop --property /backdrop


/backdrop/screen0/monitor0/brightness
/backdrop/screen0/monitor0/image-path
/backdrop/screen0/monitor0/image-show
/backdrop/screen0/monitor0/image-style
/backdrop/screen0/monitor0/last-image
/backdrop/screen0/monitor0/last-single-image
/backdrop/screen0/monitor0/workspace0/color-style
/backdrop/screen0/monitor0/workspace0/image-style
/backdrop/screen0/monitor0/workspace0/last-image
/backdrop/screen0/monitor0/workspace1/color-style
/backdrop/screen0/monitor0/workspace1/image-style
/backdrop/screen0/monitor0/workspace1/last-image
/backdrop/screen0/monitor0/workspace2/color-style
/backdrop/screen0/monitor0/workspace2/image-style
/backdrop/screen0/monitor0/workspace2/last-image
/backdrop/screen0/monitor0/workspace3/color-style
/backdrop/screen0/monitor0/workspace3/image-style
/backdrop/screen0/monitor0/workspace3/last-image
/backdrop/screen0/monitor1/brightness
/backdrop/screen0/monitor1/image-path
/backdrop/screen0/monitor1/last-image
/backdrop/screen0/monitor1/last-single-image
/backdrop/screen0/monitor2/brightness
/backdrop/screen0/monitor2/image-path
/backdrop/screen0/monitor2/last-image
/backdrop/screen0/monitor2/last-single-image
/backdrop/screen0/monitoreDP-1/workspace0/color-style
/backdrop/screen0/monitoreDP-1/workspace0/image-style
/backdrop/screen0/monitoreDP-1/workspace0/last-image
/backdrop/screen0/monitoreDP-1/workspace1/color-style
/backdrop/screen0/monitoreDP-1/workspace1/image-style
/backdrop/screen0/monitoreDP-1/workspace1/last-image
/backdrop/screen0/monitoreDP-1/workspace2/color-style
/backdrop/screen0/monitoreDP-1/workspace2/image-style
/backdrop/screen0/monitoreDP-1/workspace2/last-image
/backdrop/screen0/monitoreDP-1/workspace3/color-style
/backdrop/screen0/monitoreDP-1/workspace3/image-style
/backdrop/screen0/monitoreDP-1/workspace3/last-image
/backdrop/screen0/monitoreDP/workspace0/color-style
/backdrop/screen0/monitoreDP/workspace0/image-style
/backdrop/screen0/monitoreDP/workspace0/last-image
/backdrop/screen0/monitoreDP/workspace1/color-style
/backdrop/screen0/monitoreDP/workspace1/image-style
/backdrop/screen0/monitoreDP/workspace1/last-image
/backdrop/screen0/monitoreDP/workspace2/color-style
/backdrop/screen0/monitoreDP/workspace2/image-style
/backdrop/screen0/monitoreDP/workspace2/last-image
/backdrop/screen0/monitoreDP/workspace3/color-style
/backdrop/screen0/monitoreDP/workspace3/image-style
/backdrop/screen0/monitoreDP/workspace3/last-image

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19  8:52                       ` Po Lu
  2022-09-19 17:46                         ` Thierry Volpiatto
@ 2022-09-19 18:05                         ` Thierry Volpiatto
  2022-09-19 18:59                           ` Stefan Kangas
  2022-09-19 20:16                           ` Tomas Hlavaty
  1 sibling, 2 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-19 18:05 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1688 bytes --]


Also I noticed that anything other than worspace0 is not working from
emacs -nw, also from emacs -nw I have to extract monitor and screen
infos from command line (the emacs functions you sent are working only
on graphic display).
Here the last function I use here to test (works in emacs -nw and from
all workspaces) if that help.

(defun tv/change-xfce-background (file)
    (let* ((screen  (shell-command-to-string "echo -n $DISPLAY"))
           (monitor (shell-command-to-string
                     "echo -n $(xrandr | awk '/\\w* connected/ {print $1}')"))
           (desktop (and (display-graphic-p)
                         (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)))
           (prop    (format "/backdrop/screen%s/monitor%s/workspace%s/last-image"
                            (substring screen (1- (length screen)))
                            monitor
                            (or desktop 0)))
           (proc    (apply #'start-process "set background" nil "xfconf-query"
                           `("-c" "xfce4-desktop" "-p" ,prop "-s" ,file))))
      (set-process-sentinel
       proc (lambda (proc event)
              (if (string= event "finished\n")
                  (message "Background changed successfully to %s" (helm-basename file))
                (message "Failed to change background"))))))

Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Don't know where I can get that (/backdrop is not a directory).
>
> I meant with the `xfconf-query' program, sorry:
>
>   xfconf-query --list --recursive --channel xfce4-desktop --property /backdrop


-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19 18:05                         ` Thierry Volpiatto
@ 2022-09-19 18:59                           ` Stefan Kangas
  2022-09-19 20:16                           ` Tomas Hlavaty
  1 sibling, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-19 18:59 UTC (permalink / raw)
  To: Thierry Volpiatto, Po Lu; +Cc: emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Also I noticed that anything other than worspace0 is not working from
> emacs -nw, also from emacs -nw I have to extract monitor and screen
> infos from command line (the emacs functions you sent are working only
> on graphic display).
> Here the last function I use here to test (works in emacs -nw and from
> all workspaces) if that help.

Thanks.  I'm working on how to better handle this, and the code you
posted will definitely come in handy once I can finalize that work.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19 18:05                         ` Thierry Volpiatto
  2022-09-19 18:59                           ` Stefan Kangas
@ 2022-09-19 20:16                           ` Tomas Hlavaty
  2022-09-19 21:19                             ` Stefan Monnier
  2022-09-20  2:32                             ` Eli Zaretskii
  1 sibling, 2 replies; 61+ messages in thread
From: Tomas Hlavaty @ 2022-09-19 20:16 UTC (permalink / raw)
  To: Thierry Volpiatto, Po Lu; +Cc: Stefan Kangas, emacs-devel

On Mon 19 Sep 2022 at 18:05, Thierry Volpiatto <thievol@posteo.net> wrote:
>     (let* ((screen  (shell-command-to-string "echo -n $DISPLAY"))

would (getenv "DISPLAY") be better?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19 20:16                           ` Tomas Hlavaty
@ 2022-09-19 21:19                             ` Stefan Monnier
  2022-09-20  6:16                               ` Thierry Volpiatto
  2022-09-20  2:32                             ` Eli Zaretskii
  1 sibling, 1 reply; 61+ messages in thread
From: Stefan Monnier @ 2022-09-19 21:19 UTC (permalink / raw)
  To: Tomas Hlavaty; +Cc: Thierry Volpiatto, Po Lu, Stefan Kangas, emacs-devel

Tomas Hlavaty [2022-09-19 22:16:07] wrote:
> On Mon 19 Sep 2022 at 18:05, Thierry Volpiatto <thievol@posteo.net> wrote:
>>     (let* ((screen  (shell-command-to-string "echo -n $DISPLAY"))
> would (getenv "DISPLAY") be better?

BTW, the two will *usually* return the same result, except in the case
where the selected frame is a tty frame created via an `emacsclient`, in
which case the `DISPLAY` passed to the subprocess depends on the
`display` frame parameter.

So better use (getenv "DISPLAY" (selected-frame)) if you want to
preserve the `shell-command-to-string` behavior.


        Stefan




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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19 20:16                           ` Tomas Hlavaty
  2022-09-19 21:19                             ` Stefan Monnier
@ 2022-09-20  2:32                             ` Eli Zaretskii
  2022-09-20  2:43                               ` Po Lu
  1 sibling, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-20  2:32 UTC (permalink / raw)
  To: Tomas Hlavaty; +Cc: thievol, luangruo, stefankangas, emacs-devel

> From: Tomas Hlavaty <tom@logand.com>
> Cc: Stefan Kangas <stefankangas@gmail.com>, emacs-devel@gnu.org
> Date: Mon, 19 Sep 2022 22:16:07 +0200
> 
> On Mon 19 Sep 2022 at 18:05, Thierry Volpiatto <thievol@posteo.net> wrote:
> >     (let* ((screen  (shell-command-to-string "echo -n $DISPLAY"))
> 
> would (getenv "DISPLAY") be better?

Better by a large margin (modulo what Stefan Monnier points out).



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-20  2:32                             ` Eli Zaretskii
@ 2022-09-20  2:43                               ` Po Lu
  2022-09-20  6:25                                 ` Thierry Volpiatto
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-20  2:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Tomas Hlavaty, thievol, stefankangas, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Better by a large margin (modulo what Stefan Monnier points out).

How about (terminal-name), which is the setting that really matters
here?

Or perhaps, (frame-parameter nil 'display)?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-19 21:19                             ` Stefan Monnier
@ 2022-09-20  6:16                               ` Thierry Volpiatto
  0 siblings, 0 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-20  6:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Tomas Hlavaty, Po Lu, Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Tomas Hlavaty [2022-09-19 22:16:07] wrote:
>> On Mon 19 Sep 2022 at 18:05, Thierry Volpiatto <thievol@posteo.net> wrote:
>>>     (let* ((screen  (shell-command-to-string "echo -n $DISPLAY"))
>> would (getenv "DISPLAY") be better?
>
> BTW, the two will *usually* return the same result, except in the case
> where the selected frame is a tty frame created via an `emacsclient`, in
> which case the `DISPLAY` passed to the subprocess depends on the
> `display` frame parameter.
>
> So better use (getenv "DISPLAY" (selected-frame)) if you want to
> preserve the `shell-command-to-string` behavior.

Yes, sure getenv is better, however here:

From emacs (display-graphic-p)==t:

(getenv "DISPLAY" (selected-frame))
=> nil
(getenv "DISPLAY")
=> ":0.0"

From emacs -nw both return ":0.0".

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-20  2:43                               ` Po Lu
@ 2022-09-20  6:25                                 ` Thierry Volpiatto
  2022-09-20  8:22                                   ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-20  6:25 UTC (permalink / raw)
  To: Po Lu; +Cc: Eli Zaretskii, Tomas Hlavaty, stefankangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> Better by a large margin (modulo what Stefan Monnier points out).
>
> How about (terminal-name), which is the setting that really matters
> here?

Works on both emacs and emacs -nw.

> Or perhaps, (frame-parameter nil 'display)?

(frame-parameter nil 'display) ==>nil in emacs -nw.

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-20  6:25                                 ` Thierry Volpiatto
@ 2022-09-20  8:22                                   ` Po Lu
  0 siblings, 0 replies; 61+ messages in thread
From: Po Lu @ 2022-09-20  8:22 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Eli Zaretskii, Tomas Hlavaty, stefankangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Works on both emacs and emacs -nw.
>
>> Or perhaps, (frame-parameter nil 'display)?
>
> (frame-parameter nil 'display) ==>nil in emacs -nw.

Also, the XFCE configuration doesn't really care about DISPLAY.  So we
can only make a reasonable guess about the screen number based on the
name of the current terminal, making the assumption that it corresponds
to the same display and screen that the user's XFCE session is running
inside.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-18  1:18       ` Po Lu
  2022-09-18  2:13         ` Po Lu
  2022-09-18  4:48         ` Thierry Volpiatto
@ 2022-09-26 19:42         ` Stefan Kangas
  2022-09-26 21:01           ` Stephen Berman
                             ` (2 more replies)
  2 siblings, 3 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-26 19:42 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel, Thierry Volpiatto

Po Lu <luangruo@yahoo.com> writes:

> The screen number should be the following part of the `display' frame
> parameter:
>
>   1.1.1.1:0.5
>             ^ screen number is 5
>
> if there is no period after the separator, then the screen number is 0.
>
> The currently active workspace can be obtained like so:
>
>   (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)
>
> if it fails by returning NULL, then you should fall back to:
>
>   (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)
>
> and failing that, 0.
>
> The monitor name should also be easy to extract with
> display-monitor-attributes-list, but if the source is anything other
> than "XRandr", "XRandr 1.5" or "Gdk", you should fall back to using "0".

Thanks, I've pushed a fix to master based on the above.  I very much
appreciated the clear instructions above, which saved me a ton of time.

I had to jump through extra hoops to get it to work also in the
situation that Thierry described, however.  See commit b0289e7f6d and in
particular bb9df76dc9.

I installed XFCE on my machine to test the change and it works for me.
If someone with XFCE could test that the change works for them, that
would be welcome.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 19:42         ` Stefan Kangas
@ 2022-09-26 21:01           ` Stephen Berman
  2022-09-26 22:46             ` Stefan Kangas
  2022-09-27  0:33             ` Po Lu
  2022-09-27  5:56           ` Eli Zaretskii
  2022-09-27  7:21           ` Thierry Volpiatto
  2 siblings, 2 replies; 61+ messages in thread
From: Stephen Berman @ 2022-09-26 21:01 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Po Lu, emacs-devel, Thierry Volpiatto

On Mon, 26 Sep 2022 15:42:51 -0400 Stefan Kangas <stefankangas@gmail.com> wrote:

> Po Lu <luangruo@yahoo.com> writes:
>
>> The screen number should be the following part of the `display' frame
>> parameter:
>>
>>   1.1.1.1:0.5
>>             ^ screen number is 5
>>
>> if there is no period after the separator, then the screen number is 0.
>>
>> The currently active workspace can be obtained like so:
>>
>>   (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)
>>
>> if it fails by returning NULL, then you should fall back to:
>>
>>   (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)
>>
>> and failing that, 0.
>>
>> The monitor name should also be easy to extract with
>> display-monitor-attributes-list, but if the source is anything other
>> than "XRandr", "XRandr 1.5" or "Gdk", you should fall back to using "0".
>
> Thanks, I've pushed a fix to master based on the above.  I very much
> appreciated the clear instructions above, which saved me a ton of time.
>
> I had to jump through extra hoops to get it to work also in the
> situation that Thierry described, however.  See commit b0289e7f6d and in
> particular bb9df76dc9.
>
> I installed XFCE on my machine to test the change and it works for me.
> If someone with XFCE could test that the change works for them, that
> would be welcome.

It does not work for me.  display-monitor-attributes-list identifies my
monitor as "HDMI2", which is of course not one of the stipulated
sources.  After commenting out

(if (and monitor (member source '("XRandr" "XRandr 1.5" "Gdk")))
    monitor
  "0")

in wallpaper--format-arg and using "HDMI2" for the monitor, then
wallpaper-default-set-function produces a command that does change the
wallpaper.

In case it matters, my xfconf-query version is 4.16.0.

Steve Berman



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 21:01           ` Stephen Berman
@ 2022-09-26 22:46             ` Stefan Kangas
  2022-09-27  7:17               ` Stephen Berman
  2022-09-27  0:33             ` Po Lu
  1 sibling, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-26 22:46 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Po Lu, emacs-devel, Thierry Volpiatto

Stephen Berman <stephen.berman@gmx.net> writes:

> It does not work for me.  display-monitor-attributes-list identifies my
> monitor as "HDMI2", which is of course not one of the stipulated
> sources.  After commenting out
>
> (if (and monitor (member source '("XRandr" "XRandr 1.5" "Gdk")))
>     monitor
>   "0")
>
> in wallpaper--format-arg and using "HDMI2" for the monitor, then
> wallpaper-default-set-function produces a command that does change the
> wallpaper.

What's the full value of

    (display-monitor-attributes-list)

on your system?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 21:01           ` Stephen Berman
  2022-09-26 22:46             ` Stefan Kangas
@ 2022-09-27  0:33             ` Po Lu
  1 sibling, 0 replies; 61+ messages in thread
From: Po Lu @ 2022-09-27  0:33 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Stefan Kangas, emacs-devel, Thierry Volpiatto

Stephen Berman <stephen.berman@gmx.net> writes:

> It does not work for me.  display-monitor-attributes-list identifies my
> monitor as "HDMI2", which is of course not one of the stipulated
> sources.  After commenting out
>
> (if (and monitor (member source '("XRandr" "XRandr 1.5" "Gdk")))
>     monitor
>   "0")
>
> in wallpaper--format-arg and using "HDMI2" for the monitor, then
> wallpaper-default-set-function produces a command that does change the
> wallpaper.
>
> In case it matters, my xfconf-query version is 4.16.0.

I think you said "HDMI2" twice.  What is the actual name of the monitor?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 19:42         ` Stefan Kangas
  2022-09-26 21:01           ` Stephen Berman
@ 2022-09-27  5:56           ` Eli Zaretskii
  2022-09-27  6:13             ` Po Lu
  2022-09-27  7:21           ` Thierry Volpiatto
  2 siblings, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-27  5:56 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: luangruo, emacs-devel, thievol

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Mon, 26 Sep 2022 15:42:51 -0400
> Cc: emacs-devel@gnu.org, Thierry Volpiatto <thievol@posteo.net>
> 
> Po Lu <luangruo@yahoo.com> writes:
> 
> > The screen number should be the following part of the `display' frame
> > parameter:
> >
> >   1.1.1.1:0.5
> >             ^ screen number is 5
> >
> > if there is no period after the separator, then the screen number is 0.
> >
> > The currently active workspace can be obtained like so:
> >
> >   (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)
> >
> > if it fails by returning NULL, then you should fall back to:
> >
> >   (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)
> >
> > and failing that, 0.
> >
> > The monitor name should also be easy to extract with
> > display-monitor-attributes-list, but if the source is anything other
> > than "XRandr", "XRandr 1.5" or "Gdk", you should fall back to using "0".
> 
> Thanks, I've pushed a fix to master based on the above.  I very much
> appreciated the clear instructions above, which saved me a ton of time.

It would be good to have at least the important properties accepted by
x-window-property documented in the doc string.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  5:56           ` Eli Zaretskii
@ 2022-09-27  6:13             ` Po Lu
  2022-09-27  6:45               ` Eli Zaretskii
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-27  6:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Kangas, emacs-devel, thievol

Eli Zaretskii <eliz@gnu.org> writes:

>> Thanks, I've pushed a fix to master based on the above.  I very much
>> appreciated the clear instructions above, which saved me a ton of time.
>
> It would be good to have at least the important properties accepted by
> x-window-property documented in the doc string.

But those properties aren't specified by Emacs, they're specified by
third-party specifications, like this:

  https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html

or

  https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html

maybe it would be better to put a link to those specifications in the
doc string, instead of simply mentioning the many important properties?




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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  6:13             ` Po Lu
@ 2022-09-27  6:45               ` Eli Zaretskii
  2022-09-27  7:50                 ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-27  6:45 UTC (permalink / raw)
  To: Po Lu; +Cc: stefankangas, emacs-devel, thievol

> From: Po Lu <luangruo@yahoo.com>
> Cc: Stefan Kangas <stefankangas@gmail.com>,  emacs-devel@gnu.org,
>   thievol@posteo.net
> Date: Tue, 27 Sep 2022 14:13:15 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> Thanks, I've pushed a fix to master based on the above.  I very much
> >> appreciated the clear instructions above, which saved me a ton of time.
> >
> > It would be good to have at least the important properties accepted by
> > x-window-property documented in the doc string.
> 
> But those properties aren't specified by Emacs, they're specified by
> third-party specifications, like this:
> 
>   https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
> 
> or
> 
>   https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html
> 
> maybe it would be better to put a link to those specifications in the
> doc string, instead of simply mentioning the many important properties?

Yes, of course, mentioning those URLs will go a long way towards
filling the current gap.  If different environments/desktops have
their separate specs, I think it is best to have them all mentioned,
each one with the names of the environments/desktops for which it is
relevant.

Thanks.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 22:46             ` Stefan Kangas
@ 2022-09-27  7:17               ` Stephen Berman
  2022-09-27  7:45                 ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Stephen Berman @ 2022-09-27  7:17 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Po Lu, emacs-devel, Thierry Volpiatto

On Mon, 26 Sep 2022 18:46:47 -0400 Stefan Kangas <stefankangas@gmail.com> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>> It does not work for me.  display-monitor-attributes-list identifies my
>> monitor as "HDMI2", which is of course not one of the stipulated
>> sources.  After commenting out
>>
>> (if (and monitor (member source '("XRandr" "XRandr 1.5" "Gdk")))
>>     monitor
>>   "0")
>>
>> in wallpaper--format-arg and using "HDMI2" for the monitor, then
>> wallpaper-default-set-function produces a command that does change the
>> wallpaper.
>
> What's the full value of
>
>     (display-monitor-attributes-list)
>
> on your system?

(((name . "HDMI2") (geometry 0 0 2560 1440) (workarea 0 0 2560 1440) (mm-size 600 340) (frames #<frame  *Minibuf-1* - GNU Emacs at strobelfs2 0x2036950>) (source . "XRandR 1.5")))

On Tue, 27 Sep 2022 08:33:20 +0800 Po Lu <luangruo@yahoo.com> wrote:

[...]
> I think you said "HDMI2" twice.  What is the actual name of the monitor?

Yeah, sorry, I misread the code.  As seen above, the problem is that
display-monitor-attributes-list contains "XRandR 1.5", not "XRandr 1.5".

Steve Berman



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-26 19:42         ` Stefan Kangas
  2022-09-26 21:01           ` Stephen Berman
  2022-09-27  5:56           ` Eli Zaretskii
@ 2022-09-27  7:21           ` Thierry Volpiatto
  2022-09-27  7:42             ` Po Lu
                               ` (2 more replies)
  2 siblings, 3 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-27  7:21 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Po Lu, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 3647 bytes --]


Hello Stefan,

Stefan Kangas <stefankangas@gmail.com> writes:

> Po Lu <luangruo@yahoo.com> writes:
>
>> The screen number should be the following part of the `display' frame
>> parameter:
>>
>>   1.1.1.1:0.5
>>             ^ screen number is 5
>>
>> if there is no period after the separator, then the screen number is 0.
>>
>> The currently active workspace can be obtained like so:
>>
>>   (x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)
>>
>> if it fails by returning NULL, then you should fall back to:
>>
>>   (x-window-property "WIN_WORKSPACE" nil "CARDINAL" 0 nil t)
>>
>> and failing that, 0.
>>
>> The monitor name should also be easy to extract with
>> display-monitor-attributes-list, but if the source is anything other
>> than "XRandr", "XRandr 1.5" or "Gdk", you should fall back to using "0".
>
> Thanks, I've pushed a fix to master based on the above.  I very much
> appreciated the clear instructions above, which saved me a ton of time.
>
> I had to jump through extra hoops to get it to work also in the
> situation that Thierry described, however.  See commit b0289e7f6d and in
> particular bb9df76dc9.
>
> I installed XFCE on my machine to test the change and it works for me.
> If someone with XFCE could test that the change works for them, that
> would be welcome.

It is working fine on graphic display but on emacs -nw there is two problems:

1) The function wallpaper--format-arg is evaluating the format-specs each
time it is called and when display-graphic-p returns nil, user is
prompted for height and width at each call.

Here the xfce args:

("-c" "xfce4-desktop" "-p" "/backdrop/screen%S/monitor%M/workspace%W/last-image" "-s" "%f")

We are prompted for height and width for each of these args.

Here how you could fix this:

diff --git a/lisp/image/wallpaper.el b/lisp/image/wallpaper.el
index 36bc7e91a69..9ac0fd1dc91 100644
--- a/lisp/image/wallpaper.el
+++ b/lisp/image/wallpaper.el
@@ -374,8 +374,10 @@ See also `wallpaper-default-width'.")
 
 (defun wallpaper--get-height-or-width (desc fun default)
   (cond ((display-graphic-p) (funcall fun))
-        (noninteractive default)
-        ((read-number (format "Wallpaper %s in pixels: " desc) default))))
+        ;; (noninteractive default)
+        (t
+         (lambda ()
+           (read-number (format "Wallpaper %s in pixels: " desc) default)))))
 
 (autoload 'ffap-file-at-point "ffap")
 
@@ -444,7 +446,9 @@ This is the default function for `wallpaper-set-function'."
   (let* ((args (if (functionp wallpaper-command-args)
                    (funcall wallpaper-command-args)
                  wallpaper-command-args))
-         (real-args (mapcar (lambda (arg) (wallpaper--format-arg arg file))
+         (real-args (mapcar (lambda (arg)
+                              (let ((val (wallpaper--format-arg arg file)))
+                                (if (functionp val) (funcall val) val)))
                             args))
          (bufname (format " *wallpaper-%s*" (random)))
          (process

2) display-monitor-attributes-list doesn't return the value of monitor:

(display-monitor-attributes-list)

On graphic display it is ok:
=> (((name . "eDP")
  (geometry 0 0 1920 1080)
  (workarea 0 0 1920 1080)
  (mm-size 309 174)
  (frames #<frame  *Minibuf-1* - GNU Emacs at IPad-S340 0x55d6b2418828>)
  (source . "XRandr")))

But not on emacs -nw
=> (((geometry 0 0 238 57) (workarea 0 0 238 57) (mm-size nil nil) (frames #<frame F1 0x5636347dc460>)))

As a result the wallpaper is never set on emacs -nw.


-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:21           ` Thierry Volpiatto
@ 2022-09-27  7:42             ` Po Lu
  2022-09-27  7:55               ` Thierry Volpiatto
  2022-09-27 13:57             ` Stefan Kangas
  2022-09-29 14:16             ` master fe7c015b20: Support XFCE in wallpaper.el Stefan Kangas
  2 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-27  7:42 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> But not on emacs -nw
> => (((geometry 0 0 238 57) (workarea 0 0 238 57) (mm-size nil nil) (frames #<frame F1 0x5636347dc460>)))
>
> As a result the wallpaper is never set on emacs -nw.

Right... I think in that case the best thing to do would be to prompt
for the monitor name.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:17               ` Stephen Berman
@ 2022-09-27  7:45                 ` Po Lu
  2022-09-27 13:42                   ` Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-27  7:45 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Stefan Kangas, emacs-devel, Thierry Volpiatto

Stephen Berman <stephen.berman@gmx.net> writes:

> Yeah, sorry, I misread the code.  As seen above, the problem is that
> display-monitor-attributes-list contains "XRandR 1.5", not "XRandr 1.5".

Then it's my fault for providing bad instructions.  It should indeed be
"XRandR 1.5".

Sorry for the confusion.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  6:45               ` Eli Zaretskii
@ 2022-09-27  7:50                 ` Po Lu
  2022-09-27  7:56                   ` Eli Zaretskii
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-27  7:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: stefankangas, emacs-devel, thievol

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Po Lu <luangruo@yahoo.com>
>> Cc: Stefan Kangas <stefankangas@gmail.com>,  emacs-devel@gnu.org,
>>   thievol@posteo.net
>> Date: Tue, 27 Sep 2022 14:13:15 +0800
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> Thanks, I've pushed a fix to master based on the above.  I very much
>> >> appreciated the clear instructions above, which saved me a ton of time.
>> >
>> > It would be good to have at least the important properties accepted by
>> > x-window-property documented in the doc string.
>> 
>> But those properties aren't specified by Emacs, they're specified by
>> third-party specifications, like this:
>> 
>>   https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
>> 
>> or
>> 
>>   https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html
>> 
>> maybe it would be better to put a link to those specifications in the
>> doc string, instead of simply mentioning the many important properties?
>
> Yes, of course, mentioning those URLs will go a long way towards
> filling the current gap.  If different environments/desktops have
> their separate specs, I think it is best to have them all mentioned,
> each one with the names of the environments/desktops for which it is
> relevant.
>
> Thanks.

Different desktops do have their own properties, but they are too
numerous to list, unstandardized, and not really relevant for Emacs
users.  If the following text looks OK, I will add it to the doc string
of `x-window-property' soon:

X allows an arbitrary number of properties to be set on any window.
However, properties are most often set by the window manager or other
programs on the root window or FRAME's X window in order to communicate
information to Emacs and other programs.  Most of these properties are
specified as part of the Extended Window Manager Hints and the
Inter-Client Communication Conventions Manual, which are located here:

   https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html

and

  https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html




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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:42             ` Po Lu
@ 2022-09-27  7:55               ` Thierry Volpiatto
  2022-09-27  8:35                 ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-27  7:55 UTC (permalink / raw)
  To: Po Lu; +Cc: Stefan Kangas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]


Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> But not on emacs -nw
>> => (((geometry 0 0 238 57) (workarea 0 0 238 57) (mm-size nil nil) (frames #<frame F1 0x5636347dc460>)))
>>
>> As a result the wallpaper is never set on emacs -nw.
>
> Right... I think in that case the best thing to do would be to prompt
> for the monitor name.

Or to use xrandr directly if available.

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:50                 ` Po Lu
@ 2022-09-27  7:56                   ` Eli Zaretskii
  2022-09-27  8:31                     ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-27  7:56 UTC (permalink / raw)
  To: Po Lu; +Cc: stefankangas, emacs-devel, thievol

> From: Po Lu <luangruo@yahoo.com>
> Cc: stefankangas@gmail.com,  emacs-devel@gnu.org,  thievol@posteo.net
> Date: Tue, 27 Sep 2022 15:50:31 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Yes, of course, mentioning those URLs will go a long way towards
> > filling the current gap.  If different environments/desktops have
> > their separate specs, I think it is best to have them all mentioned,
> > each one with the names of the environments/desktops for which it is
> > relevant.
> >
> > Thanks.
> 
> Different desktops do have their own properties, but they are too
> numerous to list, unstandardized, and not really relevant for Emacs
> users.

Why should we second-guess what users will want? why not include those
other specs, even though they aren't standardized?  How many popular
desktops which have these specs are out there?

> X allows an arbitrary number of properties to be set on any window.
> However, properties are most often set by the window manager or other
> programs on the root window or FRAME's X window in order to communicate
> information to Emacs and other programs.  Most of these properties are
> specified as part of the Extended Window Manager Hints and the
> Inter-Client Communication Conventions Manual, which are located here:
> 
>    https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
> 
> and
> 
>   https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html

SGTM, thanks.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:56                   ` Eli Zaretskii
@ 2022-09-27  8:31                     ` Po Lu
  0 siblings, 0 replies; 61+ messages in thread
From: Po Lu @ 2022-09-27  8:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: stefankangas, emacs-devel, thievol

Eli Zaretskii <eliz@gnu.org> writes:

> Why should we second-guess what users will want? why not include those
> other specs, even though they aren't standardized?  How many popular
> desktops which have these specs are out there?

They aren't specified at all.  Most consist of private protocols between
a desktop (i.e. GNOME) and software written by the desktop developers
(i.e. GTK), and anyone who tries to document them will end up having to
second-guess what they were originally intended to mean.

Examples would be _GTK_FRAME_EXTENTS, _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED,
_GTK_THEME_VARIANT, GDK_VISUALS, _MOTIF_DEFAULT_BINDINGS,
_GTK_WORKAREAS_Dn, XFree86_DDC_EDIDn_RAWDATA, and
_GNOME_MAX_SCREEN_SIZE.  I only vaguely know their meanings, certainly
not enough to write any meaningful documentation about them.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:55               ` Thierry Volpiatto
@ 2022-09-27  8:35                 ` Po Lu
  2022-09-27 18:33                   ` Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Po Lu @ 2022-09-27  8:35 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Stefan Kangas, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> Or to use xrandr directly if available.

If a display is not available, what X server will the xrandr utility
connect to?  And how will you ensure the X server that the xrandr
utility connects to is correct?

(I say "xrandr utility" because XRandR is an X protocol extension, and
/usr/bin/X11/xrandr is simply a utility that connects to the X server
using that protocol extension to probe and configure video modes.
People seem to mix the two up.)



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:45                 ` Po Lu
@ 2022-09-27 13:42                   ` Stefan Kangas
  0 siblings, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 13:42 UTC (permalink / raw)
  To: Po Lu, Stephen Berman; +Cc: emacs-devel, Thierry Volpiatto

Po Lu <luangruo@yahoo.com> writes:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>> Yeah, sorry, I misread the code.  As seen above, the problem is that
>> display-monitor-attributes-list contains "XRandR 1.5", not "XRandr 1.5".
>
> Then it's my fault for providing bad instructions.  It should indeed be
> "XRandR 1.5".

OK, thanks.  I've updated the documentation I could find to mention
"XRandr 1.5" too.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:21           ` Thierry Volpiatto
  2022-09-27  7:42             ` Po Lu
@ 2022-09-27 13:57             ` Stefan Kangas
  2022-09-27 15:43               ` Visuwesh
  2022-09-29 14:16             ` master fe7c015b20: Support XFCE in wallpaper.el Stefan Kangas
  2 siblings, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 13:57 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Po Lu, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> 1) The function wallpaper--format-arg is evaluating the format-specs each
> time it is called and when display-graphic-p returns nil, user is
> prompted for height and width at each call.
>
> Here the xfce args:
>
> ("-c" "xfce4-desktop" "-p" "/backdrop/screen%S/monitor%M/workspace%W/last-image" "-s" "%f")
>
> We are prompted for height and width for each of these args.

The problem here is that all arguments to `format-spec' are evaluated
unconditionally.

Could we change `format-spec' to accept functions in the substitutions,
that are then only called when actually needed?

For example, from its docstring:

  (format-spec "su - %u %l"
               `((?u . ,(user-login-name))
                 (?l . "ls")))

Could then instead be:

  (format-spec "su - %u %l"
               `((?u . #'user-login-name)
                 (?l . "ls")))

Perhaps we should hide that behind a new optional argument though.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 13:57             ` Stefan Kangas
@ 2022-09-27 15:43               ` Visuwesh
  2022-09-27 16:19                 ` Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Visuwesh @ 2022-09-27 15:43 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Thierry Volpiatto, Po Lu, emacs-devel

[செவ்வாய் செப்டம்பர் 27, 2022] Stefan Kangas wrote:

> Could we change `format-spec' to accept functions in the substitutions,
> that are then only called when actually needed?

+1. I was thinking of raising such a proposal myself.  It seems wasteful to
pre-calculate all the specifications instead of lazily evaluating them.

>
> For example, from its docstring:
>
>   (format-spec "su - %u %l"
>                `((?u . ,(user-login-name))
>                  (?l . "ls")))
>
> Could then instead be:
>
>   (format-spec "su - %u %l"
>                `((?u . #'user-login-name)
>                  (?l . "ls")))
>
> Perhaps we should hide that behind a new optional argument though.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 15:43               ` Visuwesh
@ 2022-09-27 16:19                 ` Stefan Kangas
  2022-09-27 16:39                   ` Thierry Volpiatto
  2022-09-27 16:40                   ` Eli Zaretskii
  0 siblings, 2 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 16:19 UTC (permalink / raw)
  To: Visuwesh; +Cc: Thierry Volpiatto, Po Lu, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

Visuwesh <visuweshm@gmail.com> writes:

> [செவ்வாய் செப்டம்பர் 27, 2022] Stefan Kangas wrote:
>
>> Could we change `format-spec' to accept functions in the substitutions,
>> that are then only called when actually needed?
>
> +1. I was thinking of raising such a proposal myself.  It seems wasteful to
> pre-calculate all the specifications instead of lazily evaluating them.

The change is just the attached, plus documentation.

[-- Attachment #2: 0001-Make-format-spec-support-functions.patch --]
[-- Type: text/x-diff, Size: 2945 bytes --]

From e0a1a678e27a6a3da5e12edfcc7323c5204f6d2a Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 27 Sep 2022 18:16:51 +0200
Subject: [PATCH] Make format-spec support functions

---
 lisp/format-spec.el            | 15 +++++++++++++--
 test/lisp/format-spec-tests.el | 12 ++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lisp/format-spec.el b/lisp/format-spec.el
index 45c19aebc8..31e1d861c2 100644
--- a/lisp/format-spec.el
+++ b/lisp/format-spec.el
@@ -59,6 +59,16 @@ format-spec
 leading zeros or truncating leading characters until it's ten
 characters wide\".
 
+If the value is a function, it will be evaluated only when
+needed.  For example:
+
+  (format-spec \"%n\"
+               \\=`((?n . ,(lambda ()
+                          (read-number \"Number: \")))))
+
+Note that it is better to make sure the lambda is not quoted,
+like above, so that it is compiled by the byte-compiler.
+
 Any text properties of FORMAT are copied to the result, with any
 text properties of a %-spec itself copied to its substitution.
 
@@ -94,14 +104,15 @@ format-spec
                  (width (match-string 2))
                  (trunc (match-string 3))
                  (char (string-to-char (match-string 4)))
-                 (text (assq char specification)))
+                 (text (let ((res (cdr (assq char specification))))
+                         (if (and (functionp res)) (funcall res) res))))
             (when (and split
                        (not (= (1- beg) split-start)))
               (push (buffer-substring split-start (1- beg)) split-result))
             (cond (text
                    ;; Handle flags.
                    (setq text (format-spec--do-flags
-                               (format "%s" (cdr text))
+                               (format "%s" text)
                                (format-spec--parse-flags flags)
                                (and width (string-to-number width))
                                (and trunc (car (read-from-string trunc 1)))))
diff --git a/test/lisp/format-spec-tests.el b/test/lisp/format-spec-tests.el
index 4a3cc74c33..f137f94aaa 100644
--- a/test/lisp/format-spec-tests.el
+++ b/test/lisp/format-spec-tests.el
@@ -148,6 +148,18 @@ format-spec
              (format-spec fmt '((?b . "asd") (?a . "fgh")))
              #("fgh%asdasd" 0 3 (a b) 3 4 (c d) 7 10 (e f))))))
 
+(ert-deftest format-spec/function ()
+  (let* (called
+         (spec `((?a . "foo")
+                 (?f . ,(lambda ()
+                          (setq called t)
+                          "bar")))))
+    (should (equal (format-spec "%a" spec) "foo"))
+    (should-not called)
+    (should (equal (format-spec "%f" spec) "bar"))
+    (should called)))
+
+
 (ert-deftest format-spec-unknown ()
   (should-error (format-spec "foo %b %z zot" '((?b . "bar"))))
   (should-error (format-spec "foo %b %%%z zot" '((?b . "bar"))))
-- 
2.30.2


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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 16:19                 ` Stefan Kangas
@ 2022-09-27 16:39                   ` Thierry Volpiatto
  2022-09-27 16:40                   ` Eli Zaretskii
  1 sibling, 0 replies; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-27 16:39 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Visuwesh, Po Lu, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]


Stefan Kangas <stefankangas@gmail.com> writes:

> Visuwesh <visuweshm@gmail.com> writes:
>
>> [செவ்வாய் செப்டம்பர் 27, 2022] Stefan Kangas wrote:
>>
>>> Could we change `format-spec' to accept functions in the substitutions,
>>> that are then only called when actually needed?
>>
>> +1. I was thinking of raising such a proposal myself.  It seems wasteful to
>> pre-calculate all the specifications instead of lazily evaluating them.
>
> The change is just the attached, plus documentation.

Nice.

> [2. text/x-diff; 0001-Make-format-spec-support-functions.patch]...

(if (and (functionp res)) (funcall res) res)
    ^^^^^^^^^^^^^^^^^^^^^

-- 
Thierry

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

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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 16:19                 ` Stefan Kangas
  2022-09-27 16:39                   ` Thierry Volpiatto
@ 2022-09-27 16:40                   ` Eli Zaretskii
  2022-09-27 17:01                     ` Stefan Kangas
  1 sibling, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-27 16:40 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: visuweshm, thievol, luangruo, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Tue, 27 Sep 2022 12:19:32 -0400
> Cc: Thierry Volpiatto <thievol@posteo.net>, Po Lu <luangruo@yahoo.com>,
>  emacs-devel@gnu.org
> 
> +If the value is a function, it will be evaluated only when
> +needed.  For example:

What does it mean "only when needed" in this context?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 16:40                   ` Eli Zaretskii
@ 2022-09-27 17:01                     ` Stefan Kangas
  2022-09-27 17:14                       ` Eli Zaretskii
  0 siblings, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 17:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: visuweshm, thievol, luangruo, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> +If the value is a function, it will be evaluated only when
>> +needed.  For example:
>
> What does it mean "only when needed" in this context?

I wrote this rather quickly.

Is "only when a %-spec needs it" more clear?  It should probably say
"called" instead of "evaluated", too.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 17:01                     ` Stefan Kangas
@ 2022-09-27 17:14                       ` Eli Zaretskii
  2022-09-27 18:02                         ` Make format-spec accept a function as the substitution Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Eli Zaretskii @ 2022-09-27 17:14 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: visuweshm, thievol, luangruo, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Tue, 27 Sep 2022 13:01:11 -0400
> Cc: visuweshm@gmail.com, thievol@posteo.net, luangruo@yahoo.com, 
> 	emacs-devel@gnu.org
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> +If the value is a function, it will be evaluated only when
> >> +needed.  For example:
> >
> > What does it mean "only when needed" in this context?
> 
> I wrote this rather quickly.
> 
> Is "only when a %-spec needs it" more clear?  It should probably say
> "called" instead of "evaluated", too.

First I think you should use "substitution", not "value", because
that's how the SPECIFICATION alist is described:

  SPECIFICATION is an alist mapping format specification characters
  to their substitutions.

And then I'd suggest something like

  If the substitution for a specification character is a function, the
  function will be called only if FORMAT uses that character.



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

* Make format-spec accept a function as the substitution
  2022-09-27 17:14                       ` Eli Zaretskii
@ 2022-09-27 18:02                         ` Stefan Kangas
  2022-09-29  6:57                           ` Thierry Volpiatto
  0 siblings, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 18:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: visuweshm, thievol, luangruo, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> And then I'd suggest something like
>
>   If the substitution for a specification character is a function, the
>   function will be called only if FORMAT uses that character.

Thanks.  Please find attached a complete patch with documentation.

[-- Attachment #2: 0001-Make-format-spec-support-functions.patch --]
[-- Type: text/x-diff, Size: 4695 bytes --]

From ea1bdcc9710bb730fcf765c55875a6f102089f34 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 27 Sep 2022 18:16:51 +0200
Subject: [PATCH] Make format-spec support functions

* lisp/format-spec.el (format-spec): Allow using a format as the
substitution for a character.
* doc/lispref/strings.texi (Custom Format Strings): Document the
above change.
* test/lisp/format-spec-tests.el (format-spec/function): New test.
Ref. https://lists.gnu.org/r/emacs-devel/2022-09/msg01875.html
---
 doc/lispref/strings.texi       |  5 +++++
 etc/NEWS                       |  6 ++++++
 lisp/format-spec.el            | 16 ++++++++++++++--
 test/lisp/format-spec-tests.el | 11 +++++++++++
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 374381e595..af368f5d01 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -1293,6 +1293,11 @@ Custom Format Strings
 the order of associations in @var{spec-alist}.
 @end itemize
 
+REPLACEMENT can also be a function taking no arguments.  It will only
+be called when the corresponding LETTER is used in the TEMPLATE.  This
+is useful, for example, to avoid prompting for input unless it is
+needed.
+
 The optional argument @var{ignore-missing} indicates how to handle
 specification characters in @var{template} that are not found in
 @var{spec-alist}.  If it is @code{nil} or omitted, the function
diff --git a/etc/NEWS b/etc/NEWS
index 99243481a0..97838442db 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3910,6 +3910,12 @@ the same but works by modifying LIST destructively.
 ---
 ** 'string-split' is now an alias for 'split-string'.
 
++++
+** 'format-spec' now accepts functions in the replacement.
+The function is called only when used in the format string.  This is
+useful to avoid side-effects such as prompting, when the value is not
+actually being used for anything.
+
 +++
 ** The variable 'max-specpdl-size' has been made obsolete.
 Now 'max-lisp-eval-depth' alone is used for limiting Lisp recursion
diff --git a/lisp/format-spec.el b/lisp/format-spec.el
index 45c19aebc8..1c817ea7fa 100644
--- a/lisp/format-spec.el
+++ b/lisp/format-spec.el
@@ -59,6 +59,17 @@ format-spec
 leading zeros or truncating leading characters until it's ten
 characters wide\".
 
+If the substitution for a specification character is a function,
+the function will be called only if FORMAT uses that character.
+For example:
+
+  (format-spec \"%n\"
+               \\=`((?n . ,(lambda ()
+                          (read-number \"Number: \")))))
+
+Note that it is best to make sure the function is not quoted,
+like above, so that it is compiled by the byte-compiler.
+
 Any text properties of FORMAT are copied to the result, with any
 text properties of a %-spec itself copied to its substitution.
 
@@ -94,14 +105,15 @@ format-spec
                  (width (match-string 2))
                  (trunc (match-string 3))
                  (char (string-to-char (match-string 4)))
-                 (text (assq char specification)))
+                 (text (let ((res (cdr (assq char specification))))
+                         (if (functionp res) (funcall res) res))))
             (when (and split
                        (not (= (1- beg) split-start)))
               (push (buffer-substring split-start (1- beg)) split-result))
             (cond (text
                    ;; Handle flags.
                    (setq text (format-spec--do-flags
-                               (format "%s" (cdr text))
+                               (format "%s" text)
                                (format-spec--parse-flags flags)
                                (and width (string-to-number width))
                                (and trunc (car (read-from-string trunc 1)))))
diff --git a/test/lisp/format-spec-tests.el b/test/lisp/format-spec-tests.el
index 4a3cc74c33..bd493ae1d7 100644
--- a/test/lisp/format-spec-tests.el
+++ b/test/lisp/format-spec-tests.el
@@ -148,6 +148,17 @@ format-spec
              (format-spec fmt '((?b . "asd") (?a . "fgh")))
              #("fgh%asdasd" 0 3 (a b) 3 4 (c d) 7 10 (e f))))))
 
+(ert-deftest format-spec/function ()
+  (let* (called
+         (spec `((?a . "foo")
+                 (?f . ,(lambda ()
+                          (setq called t)
+                          "bar")))))
+    (should (equal (format-spec "%a" spec) "foo"))
+    (should-not called)
+    (should (equal (format-spec "%f" spec) "bar"))
+    (should called)))
+
 (ert-deftest format-spec-unknown ()
   (should-error (format-spec "foo %b %z zot" '((?b . "bar"))))
   (should-error (format-spec "foo %b %%%z zot" '((?b . "bar"))))
-- 
2.30.2


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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  8:35                 ` Po Lu
@ 2022-09-27 18:33                   ` Stefan Kangas
  2022-09-28  0:34                     ` Po Lu
  0 siblings, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-27 18:33 UTC (permalink / raw)
  To: Po Lu, Thierry Volpiatto; +Cc: emacs-devel

Po Lu <luangruo@yahoo.com> writes:

> Thierry Volpiatto <thievol@posteo.net> writes:
>
>> Or to use xrandr directly if available.
>
> If a display is not available, what X server will the xrandr utility
> connect to?  And how will you ensure the X server that the xrandr
> utility connects to is correct?

Won't it just use whatever is in $DISPLAY?  I'm seeing this in
"emacs -Q -nw", running in an xterm:

  ELISP> (display-monitor-attributes-list)
  (((geometry 0 0 255 78)
    (workarea 0 0 255 78)
    (mm-size nil nil)
    (frames #<frame F1 0x55f85d4ed4d0>)))
  ELISP> (getenv "DISPLAY")
  ":0"
  ELISP> (shell-command "xrandr" t)
  293 (#o445, #x125)
  ELISP> Screen 0: minimum 8 x 8, current 2560 x 1440, maximum 16384 x 16384
  DVI-I-0 disconnected primary (normal left inverted right x axis y axis)
  DVI-I-1 connected 2560x1440+0+0 (normal left inverted right x axis y
axis) 597mm x 336mm
     2560x1440     59.95*+
     1920x1200     59.88
     1920x1080     60.00
     1680x1050     59.95
     1600x1200     60.00
     1280x1024     75.02    60.02
     1280x800      59.81
     1152x864      75.00
     1024x768      75.03    60.00
     800x600       75.00    60.32
     640x480       75.00    59.94
  HDMI-0 disconnected (normal left inverted right x axis y axis)
  DP-0 disconnected (normal left inverted right x axis y axis)
  DVI-D-0 disconnected (normal left inverted right x axis y axis)
  DP-1 disconnected (normal left inverted right x axis y axis)

So it seems like we could just look for "^\\([^ ]\\)+ connected" and
just use the first one?  If nothing else, couldn't we use it to get a
default value?



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27 18:33                   ` Stefan Kangas
@ 2022-09-28  0:34                     ` Po Lu
  0 siblings, 0 replies; 61+ messages in thread
From: Po Lu @ 2022-09-28  0:34 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Thierry Volpiatto, emacs-devel

Stefan Kangas <stefankangas@gmail.com> writes:

> Won't it just use whatever is in $DISPLAY?  I'm seeing this in
> "emacs -Q -nw", running in an xterm:

Yes, but then you can do the same in Emacs:

  (x-open-connection (getenv "DISPLAY"))
  (display-monitor-attributes-list (car (last (terminal-list))))

and DISPLAY might not be set either.

>   ELISP> Screen 0: minimum 8 x 8, current 2560 x 1440, maximum 16384 x 16384
>   DVI-I-0 disconnected primary (normal left inverted right x axis y axis)
>   DVI-I-1 connected 2560x1440+0+0 (normal left inverted right x axis y
> axis) 597mm x 336mm
>      2560x1440     59.95*+
>      1920x1200     59.88
>      1920x1080     60.00
>      1680x1050     59.95
>      1600x1200     60.00
>      1280x1024     75.02    60.02
>      1280x800      59.81
>      1152x864      75.00
>      1024x768      75.03    60.00
>      800x600       75.00    60.32
>      640x480       75.00    59.94
>   HDMI-0 disconnected (normal left inverted right x axis y axis)
>   DP-0 disconnected (normal left inverted right x axis y axis)
>   DVI-D-0 disconnected (normal left inverted right x axis y axis)
>   DP-1 disconnected (normal left inverted right x axis y axis)
>
> So it seems like we could just look for "^\\([^ ]\\)+ connected" and
> just use the first one?  If nothing else, couldn't we use it to get a
> default value?

Well, then you run into the problem where the format of the texxt
returned by the XRandR utility is not exactly stable.

On servers supporting version 1.5 or later of the extension,

  xrandr --listmonitors

is also a better idea, as that is the kind of monitor XFCE will use.



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

* Re: Make format-spec accept a function as the substitution
  2022-09-27 18:02                         ` Make format-spec accept a function as the substitution Stefan Kangas
@ 2022-09-29  6:57                           ` Thierry Volpiatto
  2022-09-29 12:36                             ` Stefan Monnier
  0 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-29  6:57 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, visuweshm, luangruo, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2221 bytes --]


Hello Stefan,

Stefan Kangas <stefankangas@gmail.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> And then I'd suggest something like
>>
>>   If the substitution for a specification character is a function, the
>>   function will be called only if FORMAT uses that character.
>
> Thanks.  Please find attached a complete patch with documentation.
>
> [2. text/x-diff; 0001-Make-format-spec-support-functions.patch]...

After thinking at it, it would be great to allow using interactive calls
in specs without wrapping them inside a function:

Using this should ask for line number and file:
(format-spec "Go to line %n in file %f %g" '((?n . (read-number "Number: "))
                                             (?g . "now")
                                             (?f . (read-file-name "File: "))))

Whereas using this should not ask for anything:
(format-spec "Go to line %g" '((?n . (read-number "Number: "))
                               (?g . "now")
                               (?f . (read-file-name "File: "))))


For this specs should be looked one by one and evaluated when needed,
here a naive version of format-spec that allow this (doesn't handle 0,
space, -_> etc..):

(defun tv/format-spec-1 (format spec)
  (cl-loop with fma = format
           with result
           for (char . val) in spec
           for target = (if (string-match "%\\([[:alpha:]]\\)" fma)
                            (string-to-char (match-string 1 fma))
                          fma)
           if (eq target char)
           return (eval val t)
           finally return target))

(defun tv/format-spec (format spec)
  (let (strs fmt-str)
    (with-temp-buffer
      (save-excursion
        (insert format))
      (setq strs (cl-loop while (re-search-forward "%\\([[:alpha:]]\\)" nil t)
                          collect (match-string 0)
                          do (replace-match "s" nil nil nil 1)))
      (setq fmt-str (buffer-string)))
    (apply #'format fmt-str
           (cl-loop for str in strs
                    collect (tv/format-spec-1 str spec)))))

Probably the idea handled by this code could be ported to format-spec?

-- 
Thierry

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

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

* Re: Make format-spec accept a function as the substitution
  2022-09-29  6:57                           ` Thierry Volpiatto
@ 2022-09-29 12:36                             ` Stefan Monnier
  2022-09-29 12:59                               ` Stefan Kangas
                                                 ` (2 more replies)
  0 siblings, 3 replies; 61+ messages in thread
From: Stefan Monnier @ 2022-09-29 12:36 UTC (permalink / raw)
  To: Thierry Volpiatto
  Cc: Stefan Kangas, Eli Zaretskii, visuweshm, luangruo, emacs-devel

Thierry Volpiatto [2022-09-29 06:57:07] wrote:
> After thinking at it, it would be great to allow using interactive calls
> in specs without wrapping them inside a function:
>
> Using this should ask for line number and file:
> (format-spec "Go to line %n in file %f %g" '((?n . (read-number "Number: "))
>                                              (?g . "now")
>                                              (?f . (read-file-name "File: "))))

ELisp forms under a quote make me cringe.

Code should be quoted with `lambda` (which you run with `funcall` or
`apply`), not with `quote` (for which you need to use `eval`).

So we should aim for a source code of the form:

    (format-spec "Go to line %n in file %f %g"
                 `((?n . ,(λ () (read-number "Number: ")))
                   (?g . "now")
                   (?f . ,(λ () (read-file-name "File: ")))))


-- Stefan




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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 12:36                             ` Stefan Monnier
@ 2022-09-29 12:59                               ` Stefan Kangas
  2022-09-29 15:02                               ` Philip Kaludercic
  2022-09-29 15:09                               ` Thierry Volpiatto
  2 siblings, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-29 12:59 UTC (permalink / raw)
  To: Stefan Monnier, Thierry Volpiatto
  Cc: Eli Zaretskii, visuweshm, luangruo, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Code should be quoted with `lambda` (which you run with `funcall` or
> `apply`), not with `quote` (for which you need to use `eval`).
>
> So we should aim for a source code of the form:
>
>     (format-spec "Go to line %n in file %f %g"
>                  `((?n . ,(λ () (read-number "Number: ")))
>                    (?g . "now")
>                    (?f . ,(λ () (read-file-name "File: ")))))

I agree, which is why that's what my patch does.



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

* Re: master fe7c015b20: Support XFCE in wallpaper.el
  2022-09-27  7:21           ` Thierry Volpiatto
  2022-09-27  7:42             ` Po Lu
  2022-09-27 13:57             ` Stefan Kangas
@ 2022-09-29 14:16             ` Stefan Kangas
  2 siblings, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-29 14:16 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: Po Lu, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

> 1) The function wallpaper--format-arg is evaluating the format-specs each
> time it is called and when display-graphic-p returns nil, user is
> prompted for height and width at each call.

This should now be fixed (commit 5281946fbf and b71241742c).

> 2) display-monitor-attributes-list doesn't return the value of monitor:

I've installed a fix on master (commit 2c331dbb4e).  It works for me,
but any testing you could do would be appreciated.



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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 12:36                             ` Stefan Monnier
  2022-09-29 12:59                               ` Stefan Kangas
@ 2022-09-29 15:02                               ` Philip Kaludercic
  2022-09-29 16:34                                 ` Stefan Kangas
  2022-09-29 16:56                                 ` Stefan Monnier
  2022-09-29 15:09                               ` Thierry Volpiatto
  2 siblings, 2 replies; 61+ messages in thread
From: Philip Kaludercic @ 2022-09-29 15:02 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Thierry Volpiatto, Stefan Kangas, Eli Zaretskii, visuweshm,
	luangruo, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Thierry Volpiatto [2022-09-29 06:57:07] wrote:
>> After thinking at it, it would be great to allow using interactive calls
>> in specs without wrapping them inside a function:
>>
>> Using this should ask for line number and file:
>> (format-spec "Go to line %n in file %f %g" '((?n . (read-number "Number: "))
>>                                              (?g . "now")
>>                                              (?f . (read-file-name "File: "))))
>
> ELisp forms under a quote make me cringe.
>
> Code should be quoted with `lambda` (which you run with `funcall` or
> `apply`), not with `quote` (for which you need to use `eval`).
>
> So we should aim for a source code of the form:
>
>     (format-spec "Go to line %n in file %f %g"
>                  `((?n . ,(λ () (read-number "Number: ")))
>                    (?g . "now")
>                    (?f . ,(λ () (read-file-name "File: ")))))

Is there no worthwhile information to pass the lambda function?

(I like the λ notation by the way, would be nice to have a (defalias 'λ
#'lambda) in subr.el).

>
> -- Stefan



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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 12:36                             ` Stefan Monnier
  2022-09-29 12:59                               ` Stefan Kangas
  2022-09-29 15:02                               ` Philip Kaludercic
@ 2022-09-29 15:09                               ` Thierry Volpiatto
  2022-09-29 16:34                                 ` Stefan Kangas
  2 siblings, 1 reply; 61+ messages in thread
From: Thierry Volpiatto @ 2022-09-29 15:09 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Stefan Kangas, Eli Zaretskii, visuweshm, luangruo, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 944 bytes --]


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Thierry Volpiatto [2022-09-29 06:57:07] wrote:
>> After thinking at it, it would be great to allow using interactive calls
>> in specs without wrapping them inside a function:
>>
>> Using this should ask for line number and file:
>> (format-spec "Go to line %n in file %f %g" '((?n . (read-number "Number: "))
>>                                              (?g . "now")
>>                                              (?f . (read-file-name "File: "))))
>
> ELisp forms under a quote make me cringe.
>
> Code should be quoted with `lambda` (which you run with `funcall` or
> `apply`), not with `quote` (for which you need to use `eval`).

Ok, that's what was proposed initially and is indeed probably the best,
however I was wondering if an implementation of format-spec not
evaluating the whole alist at once but only the needed specs would be
better.

-- 
Thierry

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

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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 15:09                               ` Thierry Volpiatto
@ 2022-09-29 16:34                                 ` Stefan Kangas
  0 siblings, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-29 16:34 UTC (permalink / raw)
  To: Thierry Volpiatto, Stefan Monnier
  Cc: Eli Zaretskii, visuweshm, luangruo, emacs-devel

Thierry Volpiatto <thievol@posteo.net> writes:

>> Code should be quoted with `lambda` (which you run with `funcall` or
>> `apply`), not with `quote` (for which you need to use `eval`).
>
> Ok, that's what was proposed initially and is indeed probably the best,
> however I was wondering if an implementation of format-spec not
> evaluating the whole alist at once but only the needed specs would be
> better.

We could do it with a new macro like `read-format-spec-lazy' of course,
but I'm not sure it's worth it.  Using a lambda seems easy enough.



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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 15:02                               ` Philip Kaludercic
@ 2022-09-29 16:34                                 ` Stefan Kangas
  2022-09-29 16:53                                   ` Philip Kaludercic
  2022-09-29 16:56                                 ` Stefan Monnier
  1 sibling, 1 reply; 61+ messages in thread
From: Stefan Kangas @ 2022-09-29 16:34 UTC (permalink / raw)
  To: Philip Kaludercic, Stefan Monnier
  Cc: Thierry Volpiatto, Eli Zaretskii, visuweshm, luangruo,
	emacs-devel

Philip Kaludercic <philipk@posteo.net> writes:

> Is there no worthwhile information to pass the lambda function?

I don't know.  Any ideas?

> (I like the λ notation by the way, would be nice to have a (defalias 'λ
> #'lambda) in subr.el).

Isn't it better to do that with, e.g., `prettify-symbols-mode'?
It doesn't seem worth rewriting all the tooling to deal with λ
correctly.



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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 16:34                                 ` Stefan Kangas
@ 2022-09-29 16:53                                   ` Philip Kaludercic
  2022-09-29 17:06                                     ` Stefan Kangas
  0 siblings, 1 reply; 61+ messages in thread
From: Philip Kaludercic @ 2022-09-29 16:53 UTC (permalink / raw)
  To: Stefan Kangas
  Cc: Stefan Monnier, Thierry Volpiatto, Eli Zaretskii, visuweshm,
	luangruo, emacs-devel

Stefan Kangas <stefankangas@gmail.com> writes:

> Philip Kaludercic <philipk@posteo.net> writes:
>
>> Is there no worthwhile information to pass the lambda function?
>
> I don't know.  Any ideas?

The best I can think of would be a number, indicating what %-spec is
being replaced?

>> (I like the λ notation by the way, would be nice to have a (defalias 'λ
>> #'lambda) in subr.el).
>
> Isn't it better to do that with, e.g., `prettify-symbols-mode'?
> It doesn't seem worth rewriting all the tooling to deal with λ
> correctly.

What tooling?  Isn't Elisp unicode compatible?



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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 15:02                               ` Philip Kaludercic
  2022-09-29 16:34                                 ` Stefan Kangas
@ 2022-09-29 16:56                                 ` Stefan Monnier
  1 sibling, 0 replies; 61+ messages in thread
From: Stefan Monnier @ 2022-09-29 16:56 UTC (permalink / raw)
  To: Philip Kaludercic
  Cc: Thierry Volpiatto, Stefan Kangas, Eli Zaretskii, visuweshm,
	luangruo, emacs-devel

>>     (format-spec "Go to line %n in file %f %g"
>>                  `((?n . ,(λ () (read-number "Number: ")))
>>                    (?g . "now")
>>                    (?f . ,(λ () (read-file-name "File: ")))))
>
> Is there no worthwhile information to pass the lambda function?

I was talking in very general terms, not specific to `format-spec`.
You'd need someone more knowledgeable about `format-spec` to answer
your question.

> (I like the λ notation by the way, would be nice to have a (defalias 'λ
> #'lambda) in subr.el).

I use `prettify-symbols-mode` :-)


        Stefan




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

* Re: Make format-spec accept a function as the substitution
  2022-09-29 16:53                                   ` Philip Kaludercic
@ 2022-09-29 17:06                                     ` Stefan Kangas
  0 siblings, 0 replies; 61+ messages in thread
From: Stefan Kangas @ 2022-09-29 17:06 UTC (permalink / raw)
  To: Philip Kaludercic
  Cc: Stefan Monnier, Thierry Volpiatto, Eli Zaretskii, visuweshm,
	luangruo, emacs-devel

Philip Kaludercic <philipk@posteo.net> writes:

> What tooling?  Isn't Elisp unicode compatible?

Anywhere you look for "lambda" you now have to look for "λ", too.



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

end of thread, other threads:[~2022-09-29 17:06 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <166336105908.23797.12319380359602540227@vcs2.savannah.gnu.org>
     [not found] ` <20220916204419.B124FC00872@vcs2.savannah.gnu.org>
2022-09-17  2:00   ` master fe7c015b20: Support XFCE in wallpaper.el Po Lu
2022-09-17 18:03     ` Stefan Kangas
2022-09-18  1:18       ` Po Lu
2022-09-18  2:13         ` Po Lu
2022-09-18  4:48         ` Thierry Volpiatto
2022-09-18  5:15           ` Po Lu
2022-09-18 14:44             ` Thierry Volpiatto
2022-09-19  4:49               ` Po Lu
2022-09-19  6:06                 ` Thierry Volpiatto
2022-09-19  7:24                   ` Po Lu
2022-09-19  8:40                     ` Thierry Volpiatto
2022-09-19  8:52                       ` Po Lu
2022-09-19 17:46                         ` Thierry Volpiatto
2022-09-19 18:05                         ` Thierry Volpiatto
2022-09-19 18:59                           ` Stefan Kangas
2022-09-19 20:16                           ` Tomas Hlavaty
2022-09-19 21:19                             ` Stefan Monnier
2022-09-20  6:16                               ` Thierry Volpiatto
2022-09-20  2:32                             ` Eli Zaretskii
2022-09-20  2:43                               ` Po Lu
2022-09-20  6:25                                 ` Thierry Volpiatto
2022-09-20  8:22                                   ` Po Lu
2022-09-19  7:23                 ` Thierry Volpiatto
2022-09-26 19:42         ` Stefan Kangas
2022-09-26 21:01           ` Stephen Berman
2022-09-26 22:46             ` Stefan Kangas
2022-09-27  7:17               ` Stephen Berman
2022-09-27  7:45                 ` Po Lu
2022-09-27 13:42                   ` Stefan Kangas
2022-09-27  0:33             ` Po Lu
2022-09-27  5:56           ` Eli Zaretskii
2022-09-27  6:13             ` Po Lu
2022-09-27  6:45               ` Eli Zaretskii
2022-09-27  7:50                 ` Po Lu
2022-09-27  7:56                   ` Eli Zaretskii
2022-09-27  8:31                     ` Po Lu
2022-09-27  7:21           ` Thierry Volpiatto
2022-09-27  7:42             ` Po Lu
2022-09-27  7:55               ` Thierry Volpiatto
2022-09-27  8:35                 ` Po Lu
2022-09-27 18:33                   ` Stefan Kangas
2022-09-28  0:34                     ` Po Lu
2022-09-27 13:57             ` Stefan Kangas
2022-09-27 15:43               ` Visuwesh
2022-09-27 16:19                 ` Stefan Kangas
2022-09-27 16:39                   ` Thierry Volpiatto
2022-09-27 16:40                   ` Eli Zaretskii
2022-09-27 17:01                     ` Stefan Kangas
2022-09-27 17:14                       ` Eli Zaretskii
2022-09-27 18:02                         ` Make format-spec accept a function as the substitution Stefan Kangas
2022-09-29  6:57                           ` Thierry Volpiatto
2022-09-29 12:36                             ` Stefan Monnier
2022-09-29 12:59                               ` Stefan Kangas
2022-09-29 15:02                               ` Philip Kaludercic
2022-09-29 16:34                                 ` Stefan Kangas
2022-09-29 16:53                                   ` Philip Kaludercic
2022-09-29 17:06                                     ` Stefan Kangas
2022-09-29 16:56                                 ` Stefan Monnier
2022-09-29 15:09                               ` Thierry Volpiatto
2022-09-29 16:34                                 ` Stefan Kangas
2022-09-29 14:16             ` master fe7c015b20: Support XFCE in wallpaper.el Stefan Kangas

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.