-
Notifications
You must be signed in to change notification settings - Fork 0
/
compat.info
3300 lines (2638 loc) · 147 KB
/
compat.info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This is doccmzGF2.info, produced by makeinfo version 6.8 from
compat.texi.
Copyright © 2022-2025 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, with the Front-Cover Texts
being “A GNU Manual,” and with the Back-Cover Texts as in (a)
below. A copy of the license is included in the section entitled
“GNU Free Documentation License.”
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
modify this GNU manual.”
INFO-DIR-SECTION Emacs
START-INFO-DIR-ENTRY
* Compat: (compat). Compatibility Library for Emacs Lisp.
END-INFO-DIR-ENTRY
File: doccmzGF2.info, Node: Top, Next: Introduction, Up: (dir)
"Compat" Manual
***************
This manual documents the usage of the "Compat" Emacs lisp library, the
forward-compatibility library for Emacs Lisp, corresponding to version
30.0.2.0.
Copyright © 2022-2025 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, with the Front-Cover Texts
being “A GNU Manual,” and with the Back-Cover Texts as in (a)
below. A copy of the license is included in the section entitled
“GNU Free Documentation License.”
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
modify this GNU manual.”
* Menu:
* Introduction::
* Support::
* Development::
* Function Index::
* Variable Index::
— The Detailed Node Listing —
Introduction
* Overview::
* Usage::
* Limitations::
Support
* Emacs 25.1:: Compatibility support for Emacs 25.1
* Emacs 26.1:: Compatibility support for Emacs 26.1
* Emacs 27.1:: Compatibility support for Emacs 27.1
* Emacs 28.1:: Compatibility support for Emacs 28.1
* Emacs 29.1:: Compatibility support for Emacs 29.1
* Emacs 30.1:: Compatibility support for Emacs 30.1
File: doccmzGF2.info, Node: Introduction, Next: Support, Prev: Top, Up: Top
1 Introduction
**************
* Menu:
* Overview::
* Usage::
* Limitations::
File: doccmzGF2.info, Node: Overview, Next: Usage, Up: Introduction
1.1 Overview
============
The objective of Compat is to provide "forwards compatibility" library
for Emacs Lisp. By using Compat, an Elisp package does not have to make
the decision to either use new and useful functionality or support old
versions of Emacs.
The library provides support back until Emacs 24.4. The intended
audience are package developers that are interested in using newer
developments, without having to break compatibility.
File: doccmzGF2.info, Node: Usage, Next: Limitations, Prev: Overview, Up: Introduction
1.2 Usage
=========
The intended use-case for this library is for package developers to add
as a dependency in the header. The version of the Compat library
mirrors the version of Emacs releases. The current version of Compat
corresponds to the current Emacs release.
;; Package-Requires: ((emacs "24.4") (compat "30.0.2.0"))
There is no need to depend on ‘emacs 24.4’ specifically. One can
choose any newer version, if features not provided by Compat necessitate
it, for example bug fixes or UI improvements.
In any file where compatibility forms are used, a
(require 'compat)
should be added early on. This will load all necessary Compat
definitions. Compat loads the ‘seq’ library which is preloaded by
default on Emacs 29. Note that if Compat is installed on a recent
version of Emacs, all of the definitions are disabled at compile time,
such that no negative performance impact is incurred.
A minimal version of Compat will be present in Emacs version 30 and
newer. Packages which are part of Emacs itself and want to take
advantage of Compat, can also use ‘(require 'compat)’. The advantage of
the inclusion of a minimal Compat in Emacs is that Compat will not be
installed if you require a version newer or equal than the current Emacs
version. For example, if a package depending on Emacs 25.1 and Compat
29.1 is installed on Emacs 30.1, Compat will not be pulled in as
dependency, since Emacs 30.1 already provides the required
functionality.
Compat provides replacement functions with extended functionality for
functions that are already defined, e.g., ‘sort’ or ‘assoc’. These
functions may have changed their calling convention (additional optional
arguments) or may have changed their behavior. These functions must be
looked up explicitly with ‘compat-function’ or called explicitly with
‘compat-call’. We call them “Extended Definitions”. In contrast, newly
“Added Definitions” can be called as usual. The Compat manual
explicitly documents the calling convention of each compatibility
function.
(compat-call assoc key alist testfn) ;; Call extended `assoc'
(mapcan fun seq) ;; Call newly added `mapcan'
-- Macro: compat-call fun &rest args
This macro calls the compatibility function FUN with ARGS. Many
functions provided by Compat can be called directly without this
macro. However in the case where Compat provides an alternative
version of an existing function, the function call has to go
through ‘compat-call’. This happens for example when the calling
convention of a function has changed.
-- Macro: compat-function fun
This macro returns the compatibility function symbol for FUN. See
‘compat-call’ for a more convenient macro to directly call
compatibility functions.
If Compat is used in Emacs core packages, the macros ‘compat-call’
and ‘compat-function’ will be available in Emacs version 30 and newer.
The macros ‘compat-call’ and ‘compat-function’ are introduced by
Compat, since Compat does not advise or override existing functions.
Generally Compat is written in defensive style which is supposed to
reduce potential breakage, and to increase the chances of staying binary
compatible across releases. The extensive test coverage ensures that we
can maintain high quality, which is crucial for Compat which is not
restricted to a namespace like usual libraries.
If you intend to use a compatibility function in your code it is
recommended that you take a look at the test suite ‘compat-tests.el’.
There you can see the supported calling conventions, which are
guaranteed to work on the supported Emacs versions. We ensure this
using continuous integration. All functions provided by Compat are
covered by the test suite. There is a link to the corresponding test on
the first line of each definition.
You may want to subscribe to the compat-announce
(https://lists.sr.ht/~pkal/compat-announce) mailing list to be notified
when new versions are released or relevant changes are made. We also
provide a development mailing list
(https://lists.sr.ht/~pkal/compat-devel) (~pkal/[email protected]
<~pkal/[email protected]>).
File: doccmzGF2.info, Node: Limitations, Prev: Usage, Up: Introduction
1.3 Limitations
===============
The Compat library has a number of limitations. Complete backwards
compatibility cannot be provided due to the scope of Compat and for
technical reasons. The scope is intentionally restricted in order to
limit the size of Compat and to ensure that the library stays
maintainable.
Emacs version 24.4 is chosen as the oldest version supported by
Compat, since Elisp has seen significant changes at that version. Since
24.4 Emacs major versions consistently bump the major version number.
On the library level, subr-x was introduced in 24.4. Most popular Emacs
packages already require 24.4 or even newer versions of Emacs.
Supporting for more historical Emacs versions would complicate
maintenance while only few packages and users would benefit.
Below we list a number of reasons why certain functionality cannot be
provided. Note that in some special cases exceptions can be made and
functions can still be added to Compat even if they satisfy the criteria
from the list. In case you miss functionality which you think should
belong here, a *note report: Development. would be much appreciated.
• The additional functionality is a command or a user-facing minor or
major mode. Compat is limited to functionality on the “library
level”. Generally functions provided by Compat are
non-interactive, such that the user interface (M-x) is unaffected
by the presence of Compat.
• The function is not useful for package authors or not intended to
be used by packages, but is only useful on the configuration level.
The macro ‘setopt’ is such an example.
• Private (double dashed) functions are not ported back. If Compat
includes some private functions, they are meant purely for internal
usage.
• The added or extended function belongs to the “application level”
and not the “library level”. Features which are not preloaded
often belong to the “application level”. Application examples are
programming modes or modes like Dired, IRC and Gnus. If these
modes are extended with new functions, these are not ported back.
• An existing function or macro was extended by some new
functionality. To support these cases, the function or macro would
have to be advised. Since this is invasive and adds significant
overhead, even when the new feature is not used, Compat does not
use advices. As a compromise, compatibility functions and macros
with a changed calling convention or behavior can be accessed via
the ‘compat-function’ and ‘compat-call’ macros. In this manual we
call such definitions “Extended Definitions”. An example is the
function ‘plist-get’. Note that extended functions are subject to
closer scrutiny, since their usage via ‘compat-call’ is not
completely painless. If a particular extended function does not
see much usage or the extension yields only marginal benefits, we
may not provide it as part of Compat.
• Bug fixes are usually not ported back as part of Compat. Sometimes
library functions show wrong behavior for edge cases. In those
cases Compat could in principle provide a compatibility function
which is invoked via ‘compat-call’. Such extended definitions
would increase the maintenance burden of Compat. At the same time
the benefits would be small given that Compat does not override
existing definitions.
• The definition belongs to an Emacs core package, which is also
distributed via ELPA. Compat does not have to provide backward
compatibility for core packages since the updated package can be
installed directly from ELPA. Examples include the libraries xref,
project, seq, map and transient.
• New functionality depends on an entire new, non-trivial core
library, which is infeasible to duplicate within Compat. If a
backport of such a library is required, the preferred approach is
to either release the library separately on GNU ELPA as a core
package or as a separately maintained GNU ELPA package. An example
is the iso8601 library.
• New functionality was implemented in the C core, or depends on
external libraries that cannot be reasonably duplicated in the
scope of a compatibility library. Sometimes new functions on the C
level rely on internal data structures, which we cannot access,
rendering a backport impossible. For example a missing libxml or
libtreesitter cannot be emulated.
• The semantics of Elisp changed on a deep level. For example the
addition of big integer support in Emacs 27.1 cannot be replicated
on the level of Compat.
File: doccmzGF2.info, Node: Support, Next: Development, Prev: Introduction, Up: Top
2 Support
*********
This section goes into the features that Compat manages and doesn’t
manage to provide for each Emacs version.
* Menu:
* Emacs 25.1:: Compatibility support for Emacs 25.1
* Emacs 26.1:: Compatibility support for Emacs 26.1
* Emacs 27.1:: Compatibility support for Emacs 27.1
* Emacs 28.1:: Compatibility support for Emacs 28.1
* Emacs 29.1:: Compatibility support for Emacs 29.1
* Emacs 30.1:: Compatibility support for Emacs 30.1
File: doccmzGF2.info, Node: Emacs 25.1, Next: Emacs 26.1, Up: Support
2.1 Emacs 25.1
==============
2.1.1 Added Definitions
-----------------------
The following functions and macros are implemented in Emacs 25.1. These
functions are made available by Compat on Emacs versions older than
25.1.
-- User Option: text-quoting-style
The value of this user option is a symbol that specifies the style
Emacs should use for single quotes in the wording of help and
messages. If the option’s value is ‘curve’, the style is ‘like
this’ with curved single quotes. If the value is ‘straight’, the
style is 'like this' with straight apostrophes. If the value is
‘grave’, quotes are not translated and the style is `like this'
with grave accent and apostrophe, the standard style before Emacs
version 25. The default value ‘nil’ acts like ‘curve’ if curved
single quotes seem to be displayable, and like ‘grave’ otherwise.
This option is useful on platforms that have problems with curved
quotes. You can customize it freely according to your personal
preference.
-- Function: region-bounds
Return the boundaries of the region. Value is a list of one or
more cons cells of the form ‘(start . end)’. It will have more
than one cons cell when the region is non-contiguous, see
‘region-noncontiguous-p’ and ‘extract-rectangle-bounds’.
-- Function: region-noncontiguous-p
Return non-nil if the region contains several pieces. An example
is a rectangular region handled as a list of separate contiguous
regions for each line.
-- Macro: save-mark-and-excursion body...
This macro is like ‘save-excursion’, but also saves and restores
the mark location and ‘mark-active’. This macro does what
‘save-excursion’ did before Emacs 25.1.
-- Function: format-message string &rest objects
This function acts like ‘format’, except it also converts any grave
accents (`) and apostrophes (') in STRING as per the value of
‘text-quoting-style’.
Typically grave accent and apostrophe in the format translate to
matching curved quotes, e.g., "Missing `%s'" might result in
"Missing ‘foo’". *Note (elisp)Text Quoting Style::, for how to
influence or inhibit this translation.
*note (elisp)Formatting Strings::.
-- Function: directory-name-p filename
This function returns non-‘nil’ if FILENAME ends with a directory
separator character. This is the forward slash ‘/’ on GNU and
other POSIX-like systems; MS-Windows and MS-DOS recognize both the
forward slash and the backslash ‘\’ as directory separators.
*Note (elisp)Directory Names::.
-- Function: string-greaterp string1 string2
This function returns the result of comparing STRING1 and STRING2
in the opposite order, i.e., it is equivalent to calling
‘(string-lessp STRING2 STRING1)’.
*Note (elisp)Text Comparison::.
-- Macro: with-file-modes mode body...
This macro evaluates the BODY forms with the default permissions
for new files temporarily set to MODES (whose value is as for
‘set-file-modes’ above). When finished, it restores the original
default file permissions, and returns the value of the last form in
BODY.
This is useful for creating private files, for example.
*Note (elisp)Changing Files::.
-- Function: alist-get key alist &optional default remove
This function is similar to ‘assq’. It finds the first association
‘(KEY . VALUE)’ by comparing KEY with ALIST elements, and, if
found, returns the VALUE of that association. If no association is
found, the function returns DEFAULT.
This is a generalized variable (*note (elisp)Generalized
Variables::) that can be used to change a value with ‘setf’. When
using it to set a value, optional argument REMOVE non-‘nil’ means
to remove KEY’s association from ALIST if the new value is ‘eql’ to
DEFAULT.
*note (elisp)Association Lists::.
-- Macro: if-let (bindings...) then &rest else...
As with ‘let*’, BINDINGS will consist of ‘(SYMBOL VALUE-FORM)’
entries that are evaluated and bound sequentially. If all
VALUE-FORM evaluate to non-‘nil’ values, then THEN is evaluated as
were the case with a regular ‘let*’ expression, with all the
variables bound. If any VALUE-FORM evaluates to ‘nil’, ELSE is
evaluated, without any bound variables.
A binding may also optionally drop the SYMBOL, and simplify to
‘(VALUE-FORM)’ if only the test is of interest.
For the sake of backwards compatibility, it is possible to write a
single binding without a binding list:
(if-let* (SYMBOL (test)) foo bar)
≡
(if-let* ((SYMBOL (test))) foo bar)
-- Macro: when-let (bindings...) &rest body
As with ‘when’, if one is only interested in the case where all
BINDINGS are non-nil. Otherwise BINDINGS are interpreted just as
they are by ‘if-let*’.
-- Function: hash-table-empty hash-table
Check whether HASH-TABLE is empty (has 0 elements).
-- Macro: thread-first &rest forms
Combine FORMS into a single expression by “threading” each element
as the _first_ argument of their successor. Elements of FORMS can
either be an list of an atom.
For example, consider the threading expression and it’s equivalent
macro expansion:
(thread-first
5
(+ 20)
(/ 25)
-
(+ 40))
≡
(+ (- (/ (+ 5 20) 25)) 40)
Note how the single ‘-’ got converted into a list before threading.
This example uses arithmetic functions, but ‘thread-first’ is not
restricted to arithmetic or side-effect free code.
-- Macro: thread-last &rest forms
Combine FORMS into a single expression by “threading” each element
as the _last_ argument of their successor. Elements of FORMS can
either be an list of an atom.
For example, consider the threading expression and it’s equivalent
macro expansion:
(thread-first
5
(+ 20)
(/ 25)
-
(+ 40))
≡
(+ 40 (- (/ 25 (+ 20 5))))
Note how the single ‘-’ got converted into a list before threading.
This example uses arithmetic functions, but ‘thread-last’ is not
restricted to arithmetic or side-effect free code.
-- Function: macroexpand-1 form &optional environment
This function expands macros like ‘macroexpand’, but it only
performs one step of the expansion: if the result is another macro
call, ‘macroexpand-1’ will not expand it.
*Note Expansion: (elisp)Expansion.
-- Function: macroexp-quote e
Return an expression E such that ‘(eval e)’ is V.
-- Function: macroexp-parse body
Parse a function BODY into ‘(declarations . exps)’.
-- Function: bool-vector &rest objects
This function creates and returns a bool-vector whose elements are
the arguments, OBJECTS.
*Note (elisp)Bool-Vectors::.
2.1.2 Missing Definitions
-------------------------
Compat does not provide support for the following Lisp features
implemented in 25.1:
• The function ‘macroexp-macroexpand’.
• The macro ‘macroexp-let2*’.
• The function ‘directory-files-recursively’.
• New ‘pcase’ patterns.
• The hook ‘prefix-command-echo-keystrokes-functions’ and
‘prefix-command-preserve-state-hook’.
• The hook ‘pre-redisplay-functions’.
• The function ‘make-process’.
• Support for the variable ‘inhibit-message’.
• The ‘define-inline’ functionality.
• The functions ‘string-collate-lessp’ and ‘string-collate-equalp’.
• The function ‘funcall-interactively’.
• The function ‘buffer-substring-with-bidi-context’.
• The function ‘font-info’.
• The function ‘default-font-width’.
• The function ‘window-font-height’ and ‘window-font-width’.
• The function ‘window-max-chars-per-line’.
• The function ‘set-binary-mode’.
• The functions ‘bufferpos-to-filepos’ and ‘filepos-to-bufferpos’.
• The ‘thunk’ library.
File: doccmzGF2.info, Node: Emacs 26.1, Next: Emacs 27.1, Prev: Emacs 25.1, Up: Support
2.2 Emacs 26.1
==============
2.2.1 Added Definitions
-----------------------
The following functions and macros are implemented in Emacs 26.1. These
functions are made available by Compat on Emacs versions older than
26.1.
-- Function: assoc-delete-all key alist
This function is like ‘assq-delete-all’ except that it uses ‘equal’
to compare elements.
-- Function: read-answer question answers
This function prompts the user with text in QUESTION, which should
end in the ‘SPC’ character. The function includes in the prompt
the possible responses in ANSWERS by appending them to the end of
QUESTION. The possible responses are provided in ANSWERS as an
alist whose elements are of the following form:
(LONG-ANSWER SHORT-ANSWER HELP-MESSAGE)
where LONG-ANSWER is the complete text of the user response, a
string; SHORT-ANSWER is a short form of the same response, a single
character or a function key; and HELP-MESSAGE is the text that
describes the meaning of the answer. If the variable
‘read-answer-short’ is non-‘nil’, the prompt will show the short
variants of the possible answers and the user is expected to type
the single characters/keys shown in the prompt; otherwise the
prompt will show the long variants of the answers, and the user is
expected to type the full text of one of the answers and end by
pressing <RET>. If ‘use-dialog-box’ is non-‘nil’, and this
function was invoked by mouse events, the question and the answers
will be displayed in a GUI dialog box.
The function returns the text of the LONG-ANSWER selected by the
user, regardless of whether long or short answers were shown in the
prompt and typed by the user.
Here is an example of using this function:
(let ((read-answer-short t))
(read-answer "Foo "
'(("yes" ?y "perform the action")
("no" ?n "skip to the next")
("all" ?! "perform for the rest without more questions")
("help" ?h "show help")
("quit" ?q "exit"))))
-- Function: mapcan function sequence
This function applies FUNCTION to each element of SEQUENCE, like
‘mapcar’, but instead of collecting the results into a list, it
returns a single list with all the elements of the results (which
must be lists), by altering the results (using ‘nconc’; *note
(elisp)Rearrangement::). Like with ‘mapcar’, SEQUENCE can be of
any type except a char-table.
;; Contrast this: (mapcar #'list '(a b c d)) ⇒ ((a) (b) (c)
(d)) ;; with this: (mapcan #'list '(a b c d)) ⇒ (a b c d)
*Note (elisp)Mapping Functions::.
-- Function: cXXXr
-- Function: cXXXXr
*Note (elisp)List Elements::.
-- Function: gensym &optional prefix
This function returns a symbol using ‘make-symbol’, whose name is
made by appending ‘gensym-counter’ to PREFIX and incrementing that
counter, guaranteeing that no two calls to this function will
generate a symbol with the same name. The prefix defaults to
‘"g"’.
-- Variable: gensym-counter
See ‘gensym’.
-- Function: buffer-hash &optional buffer-or-name
Return a hash of BUFFER-OR-NAME. If ‘nil’, this defaults to the
current buffer. As opposed to ‘secure-hash’, this function
computes the hash based on the internal representation of the
buffer, disregarding any coding systems. It’s therefore only
useful when comparing two buffers running in the same Emacs, and is
not guaranteed to return the same hash between different Emacs
versions. It should be somewhat more efficient on larger buffers
than ‘secure-hash’ is, and should not allocate more memory.
-- Macro: file-name-unquote name
This macro removes the quotation prefix ‘/:’ from the file NAME, if
any. If NAME is a remote file name, the local part of NAME is
unquoted.
-- Function: file-name-quoted-p name
This macro returns non-‘nil’, when NAME is quoted with the prefix
‘/:’. If NAME is a remote file name, the local part of NAME is
checked.
*Note (elisp)File Name Expansion::.
-- Function: file-name-quote name
This macro adds the quotation prefix ‘/:’ to the file NAME. For a
local file NAME, it prefixes NAME with ‘/:’. If NAME is a remote
file name, the local part of NAME (*note (elisp)Magic File Names::)
is quoted. If NAME is already a quoted file name, NAME is returned
unchanged.
(substitute-in-file-name (compat-call file-name-quote "bar/~/foo")) ⇒
"/:bar/~/foo"
(substitute-in-file-name (compat-call file-name-quote "/ssh:host:bar/~/foo"))
⇒ "/ssh:host:/:bar/~/foo"
The macro cannot be used to suppress file name handlers from magic
file names (*note (elisp)Magic File Names::).
*Note (elisp)File Name Expansion::.
-- Function: make-nearby-temp-file prefix &optional dir-flag suffix
This function is similar to ‘make-temp-file’, but it creates a
temporary file as close as possible to ‘default-directory’. If
PREFIX is a relative file name, and ‘default-directory’ is a remote
file name or located on a mounted file systems, the temporary file
is created in the directory returned by the function
‘temporary-file-directory’. Otherwise, the function
‘make-temp-file’ is used. PREFIX, DIR-FLAG and SUFFIX have the
same meaning as in ‘make-temp-file’.
(let ((default-directory "/ssh:remotehost:")) (make-nearby-temp-file
"foo")) ⇒ "/ssh:remotehost:/tmp/foo232J6v"
-- Variable: mounted-file-systems
A regular expression matching files names that are probably on a
mounted file system.
-- Function: temporary-file-directory
The directory for writing temporary files via
‘make-nearby-temp-file’. In case of a remote ‘default-directory’,
this is a directory for temporary files on that remote host. If
such a directory does not exist, or ‘default-directory’ ought to be
located on a mounted file system (see ‘mounted-file-systems’), the
function returns ‘default-directory’. For a non-remote and
non-mounted ‘default-directory’, the value of the variable
‘temporary-file-directory’ is returned.
*Note (elisp)Unique File Names::.
-- Macro: if-let* (bindings...) then &rest else
‘if-let*’ is mostly equivalent to ‘if-let’, with the exception that
the legacy ‘(if (VAR (test)) foo bar)’ syntax is not permitted.
-- Macro: when-let* (bindings...) then &rest else
‘when-let*’ is mostly equivalent to ‘when-let’, with the exception
that the legacy ‘(when-let (VAR (test)) foo bar)’ syntax is not
permitted.
-- Macro: and-let* (bindings...) &rest body
A combination of LET* and AND, analogous to ‘when-let*’. If all
BINDINGS are non-‘nil’ and BODY is ‘nil’, then the result of the
‘and-let*’ form will be the last value bound in BINDINGS.
**Please Note:** The implementation provided by Compat does not
include a bug that was observed with Emacs 26 (see
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31840>).
-- Function: file-local-name filename
This function returns the _local part_ of FILENAME. This is the
part of the file’s name that identifies it on the remote host, and
is typically obtained by removing from the remote file name the
parts that specify the remote host and the method of accessing it.
For example:
(file-local-name "/ssh:USER@HOST:/foo/bar") ⇒
"/foo/bar"
For a remote FILENAME, this function returns a file name which
could be used directly as an argument of a remote process (*note
(elisp)Asynchronous Processes::, and *note (elisp)Synchronous
Processes::), and as the program to run on the remote host. If
FILENAME is local, this function returns it unchanged.
*Note (elisp)Magic File Names::.
-- Function: read-multiple-choice prompt choices
Ask user a multiple choice question. PROMPT should be a string
that will be displayed as the prompt.
CHOICES is an alist where the first element in each entry is a
character to be entered, the second element is a short name for the
entry to be displayed while prompting (if there’s room, it might be
shortened), and the third, optional entry is a longer explanation
that will be displayed in a help buffer if the user requests more
help.
See *note Reading One Event: (elisp)Reading One Event.
-- Function: image-property
Defined in ‘image.el’.
This function can also be used as a generalised variable.
-- Function: file-attribute-type
Return the field _type_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-link-number
Return the field _link-number_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-user-id
Return the field _user-id_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-group-id
Return the field _group-id_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-access-time
Return the field _access-time_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-modification-time
Return the field _modification-time_ as generated by
‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-status-change-time
Return the field _modification-time_ as generated by
‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-size
Return the field _size_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-modes
Return the field _modes_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-inode-number
Return the field _inode-number_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-device-number
Return the field _device-number_ as generated by ‘file-attributes’.
*Note (elisp)File Attributes::.
-- Function: file-attribute-collect attributes &rest attr-names
Filter the file attributes ATTRIBUTES, as generated by
‘file-attributes’, according to ATTR-NAMES.
Valid attribute names for ATTR-NAMES are: type, link-number,
user-id, group-id, access-time, modification-time,
status-change-time, size, modes, inode-number and device-number.
(file-attributes ".") ⇒ (t 1 1000 1000 (25329 18215 325481 96000) (25325 15364 530263 840000) (25325 15364 530263 840000) 788 "drwxr-xr-x" t 137819 40)
(file-attribute-collect (file-attributes ".") 'type 'modes
'inode-number) ⇒ (t "drwxr-xr-x" 137819)
2.2.2 Extended Definitions
--------------------------
These functions must be called explicitly via ‘compat-call’, since their
calling convention or behavior was extended in Emacs 26.1:
-- Function: compat-call make-temp-file prefix &optional dir-flag
suffix text
This function creates a temporary file and returns its name. Emacs
creates the temporary file’s name by adding to PREFIX some random
characters that are different in each Emacs job. The result is
guaranteed to be a newly created file, containing TEXT if that’s
given as a string and empty otherwise. On MS-DOS, this function
can truncate PREFIX to fit into the 8+3 file-name limits. If
PREFIX is a relative file name, it is expanded against
‘temporary-file-directory’.
The compatibility version adds support for handling the optional
argument TEXT.
(make-temp-file "foo")
⇒ "/tmp/foo232J6v"
When ‘make-temp-file’ returns, the file has been created and is
empty. At that point, you should write the intended contents into
the file.
If DIR-FLAG is non-‘nil’, ‘make-temp-file’ creates an empty
directory instead of an empty file. It returns the file name, not
the directory name, of that directory. *Note (elisp)Directory
Names::.
If SUFFIX is non-‘nil’, ‘make-temp-file’ adds it at the end of the
file name.
If TEXT is a string, ‘make-temp-file’ inserts it in the file.
To prevent conflicts among different libraries running in the same
Emacs, each Lisp program that uses ‘make-temp-file’ should have its
own PREFIX. The number added to the end of PREFIX distinguishes
between the same application running in different Emacs jobs.
Additional added characters permit a large number of distinct names
even in one Emacs job.
-- Function: compat-call assoc key alist &optional testfn
This function returns the first association for KEY in ALIST,
comparing KEY against the alist elements using TESTFN if it is a
function, and ‘equal’ otherwise (*note (elisp)Equality
Predicates::). If TESTFN is a function, it is called with two
arguments: the CAR of an element from ALIST and KEY. The function
returns ‘nil’ if no association in ALIST has a CAR equal to KEY, as
tested by TESTFN.
*Note (elisp)Association Lists::.
The compatibility version adds support for handling the optional
argument TESTFN.
-- Function: compat-call line-number-at-pos &optional pos absolute
This function returns the line number in the current buffer
corresponding to the buffer position POS. If POS is ‘nil’ or
omitted, the current buffer position is used. If ABSOLUTE is
‘nil’, the default, counting starts at ‘(point-min)’, so the value
refers to the contents of the accessible portion of the
(potentially narrowed) buffer. If ABSOLUTE is non-‘nil’, ignore
any narrowing and return
*Note (elisp)Text Lines::.
The compatibility version adds support for handling the optional
argument ABSOLUTE.
-- Function: compat-call alist-get key alist &optional default remove
testfn
*Note (elisp)Association Lists::. This function is similar to
‘assq’. It finds the first association ‘(KEY . VALUE)’ by
comparing KEY with ALIST elements, and, if found, returns the VALUE
of that association. If no association is found, the function
returns DEFAULT. Comparison of KEY against ALIST elements uses the
function specified by TESTFN, defaulting to ‘eq’.
*Note (elisp)Association Lists::.
The compatibility version handles the optional argument TESTFN. It
can also be used as a *note Generalized Variables:
(elisp)generalised variable.
-- Function: compat-call string-trim-left string &optional regexp
Remove the leading text that matches REGEXP from STRING. REGEXP
defaults to ‘[ \t\n\r]+’.
*Note (elisp)Creating Strings::.
The compatibility version handles the optional argument REGEXP.
-- Function: compat-call string-trim-right string &optional regexp
Remove the trailing text that matches REGEXP from STRING. REGEXP
defaults to ‘[ \t\n\r]+’.
*Note (elisp)Creating Strings::.
The compatibility version handles the optional argument REGEXP.
-- Function: compat-call string-trim string &optional trim-left
trim-right
Remove the leading text that matches TRIM-LEFT and trailing text
that matches TRIM-RIGHT from STRING. Both regexps default to ‘[
\t\n\r]+’.
*Note (elisp)Creating Strings::.
The compatibility version handles the optional arguments TRIM-LEFT
and TRIM-RIGHT.
2.2.3 Missing Definitions
-------------------------
Compat does not provide support for the following Lisp features
implemented in 26.1:
• The function ‘func-arity’.
• The function ‘secure-hash-algorithms’.
• The function ‘gnutls-available-p’.
• Support for records and record functions.
• The function ‘mapbacktrace’.
• The function ‘file-name-case-insensitive-p’.
• The additional elements of ‘parse-partial-sexp’.
• The function ‘add-variable-watcher’.
• The function ‘undo-amalgamate-change-group’.
• The function ‘char-from-name’
• Signalling errors when ‘length’ or ‘member’ deal with list cycles.
• The function ‘frame-list-z-order’.
• The function ‘frame-restack’.
• All changes related to ‘display-buffer’.
• The function ‘window-swap-states’.
• The function ‘string-version-lessp’.
• The ‘xdg’ library.
• The ‘svg’ library (published separately as a :core package).
File: doccmzGF2.info, Node: Emacs 27.1, Next: Emacs 28.1, Prev: Emacs 26.1, Up: Support
2.3 Emacs 27.1
==============
2.3.1 Added Definitions
-----------------------
The following functions and macros are implemented in Emacs 27.1. These
functions are made available by Compat on Emacs versions older than
27.1.
-- Function: major-mode-suspend
This function works like ‘fundamental-mode’, in that it kills all
buffer-local variables, but it also records the major mode in
effect, so that it could subsequently be restored. This function
and ‘major-mode-restore’ (described next) are useful when you need
to put a buffer under some specialized mode other than the one
Emacs chooses for it automatically, but would also like to be able
to switch back to the original mode later.
-- Function: major-mode-restore &optional avoided-modes
This function restores the major mode recorded by
‘major-mode-suspend’. If no major mode was recorded, this function
calls ‘normal-mode’, but tries to force it not to choose any modes
in AVOIDED-MODES, if that argument is non-‘nil’.
-- Function: ring-resize ring size
Set the size of RING to SIZE. If the new size is smaller, then the
oldest items in the ring are discarded.
-- Function: minibuffer-history-value
Return the value of the minibuffer input history list. If
MINIBUFFER-HISTORY-VARIABLE points to a buffer-local variable and
the minibuffer is active, return the buffer-local value for the
buffer that was current when the minibuffer was activated."
-- Macro: with-minibuffer-selected-window &rest body
Execute the forms in BODY from the minibuffer in its original
window. When used in a minibuffer window, select the window
selected just before the minibuffer was activated, and execute the
forms.
-- Function: read-char-from-minibuffer prompt &optional chars history
This function uses the minibuffer to read and return a single
character. Optionally, it ignores any input that is not a member
of CHARS, a list of accepted characters. The HISTORY argument
specifies the history list symbol to use; if it is omitted or
‘nil’, this function doesn’t use the history.
If you bind ‘help-form’ to a non-‘nil’ value while calling
‘read-char-from-minibuffer’, then pressing ‘help-char’ causes it to
evaluate ‘help-form’ and display the result.
-- Function: bignump object
This predicate tests whether its argument is a large integer, and
returns ‘t’ if so, ‘nil’ otherwise. Unlike small integers, large
integers can be ‘=’ or ‘eql’ even if they are not ‘eq’.
-- Function: fixnump object
This predicate tests whether its argument is a small integer, and
returns ‘t’ if so, ‘nil’ otherwise. Small integers can be compared
with ‘eq’.
-- Special Form: with-suppressed-warnings warnings body...
In execution, this is equivalent to ‘(progn BODY...)’, but the
compiler does not issue warnings for the specified conditions in
BODY. WARNINGS is an association list of warning symbols and
function/variable symbols they apply to. For instance, if you wish
to call an obsolete function called ‘foo’, but want to suppress the
compilation warning, say:
(with-suppressed-warnings ((obsolete foo))
(foo ...))
-- Function: proper-list-p object
This function returns the length of OBJECT if it is a proper list,
‘nil’ otherwise (*note (elisp)Cons Cells::). In addition to
satisfying ‘listp’, a proper list is neither circular nor dotted.
(proper-list-p '(a b c)) ⇒ 3
(proper-list-p '(a b . c)) ⇒ nil