unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help making a map-do/seq-do based code work on emacs 26.3
@ 2022-05-04 18:50 Kaushal Modi
  2022-05-04 19:20 ` Emanuel Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kaushal Modi @ 2022-05-04 18:50 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list, Nicolas Petton

Hello,

I recently published the tomelr package on GNU ELPA that can take in a
plist or alist and return a TOML string.

Now I need to tackle a small problem that makes the package fail at
run-time only on emacs 26.3 (not on emacs 27+) when a plist is passed
to its tomelr-encode function.

Recipe to reproduce failure:

1. Load emacs 26.3
2. Install tomelr from GNU ELPA
3. (require 'tomelr)
4. M-: (tomelr-encode '(:int 123))

Error backtrace

Test test-plist backtrace:
  #f(compiled-function (pair) #<bytecode 0x313eed>)(:int)
  mapc(#f(compiled-function (pair) #<bytecode 0x313eed>) (:int 123))
  seq-do(#f(compiled-function (pair) #<bytecode 0x313eed>) (:int 123))
  map--do-alist(tomelr--print-pair (:int 123))
  map-do(tomelr--print-pair (:int 123))
  (let ((tomelr--print-indentation-depth (1+ tomelr--print-indentation
  (if (map-empty-p map) nil (let ((tomelr--print-indentation-depth (1+
  tomelr--print-map((:int 123))
  (cond ((tomelr-toml-table-p list) (tomelr--print-map list)) ((listp
  tomelr--print-list((:int 123))
  (cond ((tomelr--print-boolean object)) ((listp object) (tomelr--prin
  tomelr--print((:int 123))
  (save-current-buffer (set-buffer standard-output) (set (make-local-v
  (let ((standard-output standard-output)) (save-current-buffer (set-b
  (progn (let ((standard-output standard-output)) (save-current-buffer
  (unwind-protect (progn (let ((standard-output standard-output)) (sav
  (let ((standard-output (get-buffer-create (generate-new-buffer-name
  (string-trim (let ((standard-output (get-buffer-create (generate-new
  tomelr-encode((:int 123))

Expected output:

"int = 123"


Same error on the package's CI for reference:
https://github.com/kaushalmodi/tomelr/runs/6295315125?check_suite_focus=true

===

- Is there a function or few of them that I can override so that
(tomelr-encode '(:int 123)) works on emacs 26.3 as well?
- Can I force install map and seq from GNU ELPA on emacs 26.3? But how
can I do that if a user's package.el is installing tomelr.el from GNU
ELPA as a dependency? Also package.el will refuse to install map and
seq because they are already present in Emacs 26.3 core.

--
Kaushal Modi



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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-04 18:50 Help making a map-do/seq-do based code work on emacs 26.3 Kaushal Modi
@ 2022-05-04 19:20 ` Emanuel Berg
  2022-05-05  2:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-05 16:24 ` Kaushal Modi
  2 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2022-05-04 19:20 UTC (permalink / raw)
  To: help-gnu-emacs

Kaushal Modi wrote:

> I recently published the tomelr package on GNU ELPA that can
> take in a plist or alist and return a TOML string.

TOML 2013 Tom's Obvious, Minimal Language. .toml config file format

https://dataswamp.org/~incal/COMP-HIST

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




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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-04 18:50 Help making a map-do/seq-do based code work on emacs 26.3 Kaushal Modi
  2022-05-04 19:20 ` Emanuel Berg
@ 2022-05-05  2:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-05 16:24 ` Kaushal Modi
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-05-05  2:20 UTC (permalink / raw)
  To: help-gnu-emacs

Kaushal Modi [2022-05-04 14:50:37] wrote:

> Hello,
>
> I recently published the tomelr package on GNU ELPA that can take in a
> plist or alist and return a TOML string.
>
> Now I need to tackle a small problem that makes the package fail at
> run-time only on emacs 26.3 (not on emacs 27+) when a plist is passed
> to its tomelr-encode function.
>
> Recipe to reproduce failure:
>
> 1. Load emacs 26.3
> 2. Install tomelr from GNU ELPA
> 3. (require 'tomelr)
> 4. M-: (tomelr-encode '(:int 123))
>
> Error backtrace
>
> Test test-plist backtrace:
>   #f(compiled-function (pair) #<bytecode 0x313eed>)(:int)
>   mapc(#f(compiled-function (pair) #<bytecode 0x313eed>) (:int 123))
>   seq-do(#f(compiled-function (pair) #<bytecode 0x313eed>) (:int 123))
>   map--do-alist(tomelr--print-pair (:int 123))
>   map-do(tomelr--print-pair (:int 123))

    % grep -C2 plist etc/NEWS.27
    ** map.el
    
    *** Now also understands plists.
    *** Now defined via generic functions that can be extended via 'cl-defmethod'.
    *** Deprecate the 'map-put' macro in favor of a new 'map-put!' function.
    %

IOW, you need a map that's more recent than the one that comes with Emacs<27.

> - Is there a function or few of them that I can override so that
> (tomelr-encode '(:int 123)) works on emacs 26.3 as well?

You can use something else than the `map` library.  The `map` library in
Emacs-26 doesn't make it easy to extend :-(

> - Can I force install map and seq from GNU ELPA on emacs 26.3?

For `seq`, yes, but `map` is not in GNU ELPA.

> But how can I do that if a user's package.el is installing tomelr.el
> from GNU ELPA as a dependency?

For `seq`, just add the dependency on the corresponding version of `seq`
in `Package-Requires:`.

> Also package.el will refuse to install map and
> seq because they are already present in Emacs 26.3 core.

No, if the builtin package is older, it will (modulo bugs, as always)
install (and use) the version from GNU ELPA.


        Stefan




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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-04 18:50 Help making a map-do/seq-do based code work on emacs 26.3 Kaushal Modi
  2022-05-04 19:20 ` Emanuel Berg
  2022-05-05  2:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-05-05 16:24 ` Kaushal Modi
  2022-05-05 18:32   ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Kaushal Modi @ 2022-05-05 16:24 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list, Nicolas Petton, Stefan Monnier

Hi Stefan,

Thanks for your reply.

(I realized that I had got auto-unsubscribed from this mailing list!
But I later found your reply online at
https://lists.gnu.org/r/help-gnu-emacs/2022-05/msg00027.html
I have now re-subscribed.).

> For `seq`, yes, but `map` is not in GNU ELPA.

map is actually available from GNU ELPA.

I tried adding this to tomelr.el and it worked!!

===
;; Package-Requires: ((emacs "26.3") (map "3.2.1") (seq "2.23"))
===

I couldn't do (package-install 'map) from an emacs 26.3 session. But
running (package-install-file "tomelr.el") installed the newer map and
seq from GNU ELPA.
So I am hoping that when a user installs the new tomelr version from
GNU ELPA (on Emacs 26.3), it will install the newer map and seq
versions for them as well.

I have now added this to the CI setup, which now seems to work for
emacs 26.3 too:

===(defun tomelr-install ()
  "Test installation of `tomelr' including all its dependencies."
  (let ((tomelr-site-git-root (progn
                                (require 'vc-git)
                                (file-truename (vc-git-root
default-directory)))))

    (setq package-user-dir (let ((elpa-dir-name (format "elpa_%s"
emacs-major-version))) ;default = "elpa"
                             (file-name-as-directory (expand-file-name
elpa-dir-name user-emacs-directory))))

    ;; Below require will auto-create `package-user-dir' it doesn't exist.
    (require 'package)

    ;; Load emacs packages and activate them.
    ;; Don't delete this line.
    (package-initialize)                  ;
    ;; `package-initialize' call is required before any of the below
    ;; can happen.

    (message "Emacs is now refreshing its package database...")
    (package-refresh-contents)

    (package-install-file (expand-file-name "tomelr.el" tomelr-site-git-root))
    ;; (message "package-user-dir: %S" package-user-dir)
    ;; (message "load-path: %S" load-path)
    ))

(tomelr-install)
===

Finally passing the plist test on 26.3 too :
https://github.com/kaushalmodi/tomelr/runs/6309842382?check_suite_focus=true
 :)



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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-05 16:24 ` Kaushal Modi
@ 2022-05-05 18:32   ` Stefan Monnier
  2022-05-05 21:23     ` Kaushal Modi
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2022-05-05 18:32 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: Help Gnu Emacs mailing list, Nicolas Petton

>> For `seq`, yes, but `map` is not in GNU ELPA.
> map is actually available from GNU ELPA.

Indeed, I didn't check carefully enough.  Even better!

> I couldn't do (package-install 'map) from an emacs 26.3 session.

My crystal ball says it's just because of a lack of
`package-refresh-contents` or something like that somewhere.

> But running (package-install-file "tomelr.el") installed the newer map
> and seq from GNU ELPA.

Great.

> So I am hoping that when a user installs the new tomelr version from
> GNU ELPA (on Emacs 26.3), it will install the newer map and seq
> versions for them as well.

It will, indeed.

> ===(defun tomelr-install ()
[...]
>     ;; Below require will auto-create `package-user-dir' it doesn't exist.
>     (require 'package)
>
>     ;; Load emacs packages and activate them.
>     ;; Don't delete this line.
>     (package-initialize)                  ;
>     ;; `package-initialize' call is required before any of the below
>     ;; can happen.

This call to `package-initialize` should not be necessary on recent
Emacsen (but it used to be needed, indeed).  If you find it's still
necessary with Emacs `master`, please report it as a bug.


        Stefan




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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-05 18:32   ` Stefan Monnier
@ 2022-05-05 21:23     ` Kaushal Modi
  2022-05-05 21:33       ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Kaushal Modi @ 2022-05-05 21:23 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Help Gnu Emacs mailing list, Nicolas Petton

On Thu, May 5, 2022 at 2:32 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> This call to `package-initialize` should not be necessary on recent
> Emacsen (but it used to be needed, indeed).  If you find it's still
> necessary with Emacs `master`, please report it as a bug.

Yes, I kept it there for simplicity as the CI runs on older Emacs
versions like 26.3. You're right; I don't need it for Emacs 27+.



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

* Re: Help making a map-do/seq-do based code work on emacs 26.3
  2022-05-05 21:23     ` Kaushal Modi
@ 2022-05-05 21:33       ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-05-05 21:33 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: Help Gnu Emacs mailing list, Nicolas Petton

Kaushal Modi [2022-05-05 17:23:03] wrote:
> On Thu, May 5, 2022 at 2:32 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> This call to `package-initialize` should not be necessary on recent
>> Emacsen (but it used to be needed, indeed).  If you find it's still
>> necessary with Emacs `master`, please report it as a bug.
>
> Yes, I kept it there for simplicity as the CI runs on older Emacs
> versions like 26.3. You're right; I don't need it for Emacs 27+.

Great, thanks for confirming (I always worry that I missed a spot ;-)


        Stefan




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

end of thread, other threads:[~2022-05-05 21:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-04 18:50 Help making a map-do/seq-do based code work on emacs 26.3 Kaushal Modi
2022-05-04 19:20 ` Emanuel Berg
2022-05-05  2:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-05-05 16:24 ` Kaushal Modi
2022-05-05 18:32   ` Stefan Monnier
2022-05-05 21:23     ` Kaushal Modi
2022-05-05 21:33       ` Stefan Monnier

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