commit 91851fbbf537392ead08105748f480532e7d1c50 (HEAD, refs/remotes/origin/master) Author: Jim Porter Date: Sun Aug 25 11:37:44 2024 -0700 Add manual tests for the 'min-width' display property * test/manual/redisplay-testsuite.el (test-redisplay-5): Add some newlines. (test-redisplay-6): New function... (test-redisplay): ... call it (bug#72721). diff --git a/test/manual/redisplay-testsuite.el b/test/manual/redisplay-testsuite.el index 6d1232999ca..0f13c3da417 100644 --- a/test/manual/redisplay-testsuite.el +++ b/test/manual/redisplay-testsuite.el @@ -331,7 +331,60 @@ static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff (test-insert-overlay " " 'display (char-to-string #x3fffc))) (insert "\n\n") (insert-button "Toggle between octal and hex display" - 'action 'test-redisplay-5-toggle)) + 'action 'test-redisplay-5-toggle) + (insert "\n\n")) + +(defun test-redisplay-6 () + (insert "Test 6: min-width display property:\n\n") + (insert " Expected: 123 45\n") + (insert " Results: " + (propertize "123" 'display '((min-width (5)))) + "45") + (insert "\n\n") + (insert " Expected: 12 34 5\n") + (insert " Results: " + (propertize "12" 'display '((min-width (4)))) + (propertize "34" 'display '((min-width (4)))) + "5") + (insert "\n\n") + (insert " Expected: 1gnu 45\n") + (insert " Results: " + "1" + (propertize "23" 'display + (propertize "gnu" 'display '((min-width (5))))) + "45") + (insert "\n\n") + (insert " Expected: 123 45\n") + (insert " Results: ") + (test-insert-overlay "123" 'display '((min-width (5)))) + (insert "45") + (insert "\n\n") + (insert " Expected: 1_23 45\n") + (insert " Results: ") + (insert (propertize "123" 'display '((min-width (5))))) + (let ((overlay (make-overlay (- (point) 1) (- (point) 2)))) + (overlay-put overlay 'before-string "_")) + (insert "45") + (insert "\n\n") + (insert (propertize "_" 'display '(left-fringe large-circle)) + " Expected: 123 45\n") + (insert " Results: ") + (insert (propertize "123" 'display '((min-width (5))))) + (let ((overlay (make-overlay (- (point) 2) (- (point) 1)))) + (overlay-put overlay 'before-string + (propertize "_" 'display '(left-fringe large-circle)))) + (insert "45") + (insert "\n\n") + (insert (propertize "_" 'display '(left-fringe large-circle)) + " Expected: 123 45\n") + (insert " Results: ") + (insert (propertize "123" 'display '((min-width (5))))) + (let ((overlay1 (make-overlay (- (point) 3) (point))) + (overlay2 (make-overlay (- (point) 2) (- (point) 1)))) + (overlay-put overlay1 'display '((min-width (5)))) + (overlay-put overlay2 'before-string + (propertize "_" 'display '(left-fringe large-circle)))) + (insert "45")) (defun test-redisplay () (interactive) @@ -349,6 +402,7 @@ static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff (test-redisplay-3) (test-redisplay-4) (test-redisplay-5) + (test-redisplay-6) (goto-char (point-min)))) ;;; redisplay-testsuite.el ends here commit 00f9927693ae31868d1e9f676cd2cd9d8446cb59 Author: Michael Albinus Date: Thu Aug 29 15:52:16 2024 +0200 ; Fix typos * doc/lispref/control.texi (cond* Macro): * etc/NEWS: Fix typos. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index d28505411df..399b7ee562d 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -1411,7 +1411,7 @@ argument: @end defmac @node cond* Macro -@subsection The @code{pcase} macro +@subsection The @code{cond*} macro @findex cond*@r{, a macro} The @code{cond*} macro is an alternative to @code{pcase}, and supports diff --git a/etc/NEWS b/etc/NEWS index 7554af5e3df..f3e719a34d3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -343,7 +343,7 @@ The new macro 'cond*' is an alternative to 'pcase'. Like 'pcase', it allows to define several clauses, each one of with its own condition; the first clause that matches will cause its body to be evaluated. 'cond*' uses syntax that is different from that of 'pcase', which some -users might find less cryptic. See the Info node "(elisp) cond Macro" +users might find less cryptic. See the Info node "(elisp) cond* Macro" for details. commit 38650b630bdb8b105a7e3c917cc8053133681abc Author: Eli Zaretskii Date: Thu Aug 29 12:02:08 2024 +0300 Document 'cond*' * doc/lispref/control.texi (cond* Macro): New subsection. Text written by Richard Stallman . * etc/NEWS: Document 'cond*'. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 15393f1d7f7..d28505411df 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -537,6 +537,7 @@ sometimes ``the value matches the pattern''). * Extending @code{pcase}: Extending pcase. Define new kinds of patterns. * Backquote-Style Patterns: Backquote Patterns. Structural patterns matching. * Destructuring with pcase Patterns:: Using pcase patterns to extract subfields. +* The @code{cond*} macro: cond* Macro. Alternative to @code{pcase}. @end menu @node pcase Macro @@ -1409,6 +1410,145 @@ argument: @end example @end defmac +@node cond* Macro +@subsection The @code{pcase} macro +@findex cond*@r{, a macro} + + The @code{cond*} macro is an alternative to @code{pcase}, and supports +the same functionality, but using syntax that some might find less +cryptic. + +@defmac cond* &rest clauses +The @code{cond*} macro is an extended form of the traditional +@code{cond}. A @code{cond*} expression contains a series of +@var{clauses}, each of which can use @code{bind*} to specify binding +variables, use @code{match*} to specify matching a pattern as a +condition, or specify an expression as a condition to evaluate as a +test. + +Each clause normally has the form @w{@code{(@var{condition} +@var{body}@dots{})}}. + +@var{condition} can be a Lisp expression, as in @code{cond} +(@pxref{Conditionals}). Or it can be @w{@code{(bind* +@var{bindings}@dots{})}} or @w{@code{(match* @var{pattern} +@var{datum})}}. + +@findex bind* +@code{(bind* @var{bindings}@dots{})} means to bind @var{bindings} (like +the bindings list in @code{let*}, @pxref{Local Variables}) for the body +of the clause. As a condition, it counts as true if the first binding's +value is non-@code{nil}. + +@findex match* +@code{(match* @var{pattern} @var{datum})} means to match @var{datum} +against the specified @var{pattern}. The condition counts as true if +@var{pattern} matches @var{datum}. The pattern can specify variables to +bind to the parts of @var{datum} that they match. + +Both @code{bind*} and @code{match*} normally bind their bindings over +the execution of the whole containing clause. However, if the clause is +written to specify ``non-exit'', the clause's bindings cover the whole +rest of the @code{cond*}. + +When a clause's condition is true, and it exits the @code{cond*} or is +the last clause, the value of the last expression in the clause's body +becomes the return value of the @code{cond*} construct. + +@subheading Non-exit clause + +If a clause has only one element, or if its first element is @code{t}, +or if it ends with the keyword @code{:non-exit}, then this clause never +exits the @code{cond*} construct. Instead, control falls through to the +next clause (if any). The bindings made in @var{condition} for the +@var{body} of the non-exit clause are passed along to the rest of the +clauses in this @code{cond*} construct. + +@subheading Matching clauses + +A matching clause looks like @code{(match* @var{pattern} @var{datum})}. +It evaluates the expression @var{datum} and matches the pattern +@var{pattern} (which is not evaluated) against it. + +@var{pattern} allows these kinds of patterns, and those that are lists +often include other patters within them: + +@table @code +@item _ +Matches any value. +@item @var{keyword} +Matches that keyword. +@item nil +Matches @code{nil}. +@item t +Matches @code{t}. +@item @var{symbol} +Matches any value and binds @var{symbol} to that value. If @var{symbol} +has been matched and bound earlier in this pattern, it matches here the +same value that it matched before. +@item @var{regexp} +Matches a string if @var{regexp} matches it. The match must cover the +entire string from its first char to its last. +@item @var{atom} +(Meaning any other kind of non-list not described above.) Matches +anything `equal' to it. +@item (rx @var{regexp}) +Uses a regexp specified in s-expression form, as in the function +@code{rx} (@pxref{Rx Notation}, and matches the data that way. +@item (rx @var{regexp} @var{sym0} @var{sym1}@dots{}) +Uses a regexp specified in s-expression form, and binds the symbols +@var{sym0}, @var{sym1}, and so on to @w{@code{(match-string 0 +@var{datum})}}, @w{@code{(match-string 1 @var{datum})}}, and so on. You +can use as many @var{sym}s as regexp matching supports. +@item `@var{object} +Matches any value @code{equal} to @var{object}. +@item (cons @var{carpat} @code{cdrpat}) +Matches a cons cell if @var{carpat} matches its @code{car} and +@var{cdrpat} matches its @code{cdr}. +@item (list @var{eltpats}@dots{}) +Matches a list if the @var{eltpats} match its elements. The first +@var{eltpat} should match the list's first element. The second +@var{eltpat} should match the list's second element. And so on. +@item (vector @var{eltpats}@dots{}) +Matches a vector if the @var{eltpats} match its elements. The first +@var{eltpat} should match the vector's first element. The second +@var{eltpat} should match the vector's second element. And so on. +@item (cdr @var{pattern}) +Matches @var{pattern} with strict checking of @code{cdr}s. That means +that @code{list} patterns verify that the final @code{cdr} is +@code{nil}. Strict checking is the default. +@item (cdr-safe @var{pattern}) +Matches @var{pattern} with lax checking of @code{cdr}s. That means that +@code{list} patterns do not examine the final @code{cdr}. +@item (and @var{conjuncts}@dots{}) +Matches each of the @var{conjuncts} against the same data. If all of +them match, this pattern succeeds. If one @var{conjunct} fails, this +pattern fails and does not try more @var{conjuncts}. +@item (or @var{disjuncts}@dots{}) +Matches each of the @var{disjuncts} against the same data. If one +@var{disjunct} succeeds, this pattern succeeds and does not try more +@var{disjuncts}. If all of them fail, this pattern fails. +@item (@var{cond*-expander} @dots{}) +Here the @code{car} is a symbol that has a @code{cond*-expander} +property which defines how to handle it in a pattern. The property +value is a function. Trying to match such a pattern calls that function +with one argument, the pattern in question (including its @code{car}). +The function should return an equivalent pattern to be matched instead. +@item (@var{predicate} @var{symbol}) +Matches datum if @code{(@var{predicate} @var{datum})} is true, then +binds @var{symbol} to @var{datum}. +@item (@var{predicate} @var{SYMBOL} @var{more-args}@dots{}) +Matches datum if @w{@code{(@var{predicate} @var{datum} +@var{more-args}@dots{})}} is true, then binds @var{symbol} to +@var{datum}. @var{more-args}@dots{} can refer to symbols bound earlier +in the pattern. +@item (constrain @var{symbol} @var{exp}) +Matches datum if the form @var{exp} is true. @var{exp} can refer to +symbols bound earlier in the pattern. +@end table + +@end defmac + @node Iteration @section Iteration @cindex iteration diff --git a/etc/NEWS b/etc/NEWS index 07d1cce0966..7554af5e3df 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -337,6 +337,15 @@ This 'display' property was previously supported only as text property. Now overlays can also have this property, with the same effect for the text "covered" by the overlay. ++++ +** New macro 'cond*'. +The new macro 'cond*' is an alternative to 'pcase'. Like 'pcase', it +allows to define several clauses, each one of with its own condition; +the first clause that matches will cause its body to be evaluated. +'cond*' uses syntax that is different from that of 'pcase', which some +users might find less cryptic. See the Info node "(elisp) cond Macro" +for details. + * Changes in Emacs 31.1 on Non-Free Operating Systems