zsh-workers
 help / color / mirror / Atom feed
* [PATCH] FAQ update for aliasing
@ 2021-01-29 19:35 Bart Schaefer
  2021-02-01 16:13 ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2021-01-29 19:35 UTC (permalink / raw)
  To: Zsh hackers list

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

The section on csh-to-zsh alias equivalence had a number of
not-incorrect but not-up-to-date references.  Attached patch fixes
these.

However, when I do "cd Etc; make FAQ" on Ubuntu 20.04.1 LTS, I get
some strange formatting.  Hopefully you can see what I mean in the
copy-paste below despite possible gmail line wrap:

--- 8< ---
Here is Bart Schaefer's guide to converting csh aliases for zsh.


  1. ) If the csh alias references "parameters" (\!:1, \!* etc.),
     then in zsh you need a function (referencing $1, $* etc.).
     In recent versions of zsh this can be done by defining an anonymous
     function within the alias.  Otherwise, a simple zsh alias suffices.

2. ) If you use a zsh function, you need to refer _at_least_ to
     $* in the body (inside the { }).  Parameters don't magically
     appear inside the { } the way they get appended to an alias.
--- 8< ---

That is, most paragraphs get a hanging left indent (outdent?), but not
all do.  This happens in other sections, not just the one touched in
the patch.  I'm not sure the hanging leader is even intentional.  Do
others see this?

[-- Attachment #2: faq-diff.txt --]
[-- Type: text/plain, Size: 1690 bytes --]

diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo
index a4ffba688..7aeddd89c 100644
--- a/Etc/FAQ.yo
+++ b/Etc/FAQ.yo
@@ -715,7 +715,8 @@ label(23)
   enumeration(
   myeit() If the csh alias references "parameters" (tt(\!:1), tt(\!*) etc.),
      then in zsh you need a function (referencing tt($1), tt($*) etc.).
-     Otherwise, you can use a zsh alias.
+     In recent versions of zsh this can be done by defining an anonymous
+     function within the alias.  Otherwise, a simple zsh alias suffices.
 
   myeit() If you use a zsh function, you need to refer _at_least_ to
      tt($*) in the body (inside the tt({ })).  Parameters don't magically
@@ -759,7 +760,7 @@ label(23)
      parameters. (E.g., in a csh alias, a reference to tt(\!:5) will
      cause an error if 4 or fewer arguments are given; in a zsh
      function, tt($5) is the empty string if there are 4 or fewer
-     parameters.)
+     parameters.  Force an error in this example by using tt(${5?}).)
 
   myeit() To begin a zsh alias with a - (dash, hyphen) character, use
      mytt(alias --):
@@ -780,9 +781,8 @@ label(23)
   )
   mytt(l) in the function definition is in command position and is expanded
   as an alias, defining mytt(/bin/ls) and mytt(-F) as functions which call
-  mytt(/bin/ls), which gets a bit recursive.  This can be avoided if you use
-  mytt(function) to define a function, which doesn't expand aliases.  It is
-  possible to argue for extra warnings somewhere in this mess.
+  mytt(/bin/ls), which gets a bit recursive.  Recent versions of zsh treat
+  this as an error, but older versions silently create the functions.
 
   One workaround for this is to use the "function" keyword instead:
   verb(

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

* Re: [PATCH] FAQ update for aliasing
  2021-01-29 19:35 [PATCH] FAQ update for aliasing Bart Schaefer
@ 2021-02-01 16:13 ` Daniel Shahaf
  2021-02-01 20:11   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2021-02-01 16:13 UTC (permalink / raw)
  To: Zsh hackers list

Bart Schaefer wrote on Fri, Jan 29, 2021 at 11:35:28 -0800:
> The section on csh-to-zsh alias equivalence had a number of
> not-incorrect but not-up-to-date references.  Attached patch fixes
> these.
> 
> However, when I do "cd Etc; make FAQ" on Ubuntu 20.04.1 LTS, I get
> some strange formatting.  Hopefully you can see what I mean in the
> copy-paste below despite possible gmail line wrap:
> 
> --- 8< ---
> Here is Bart Schaefer's guide to converting csh aliases for zsh.
> 
> 
>   1. ) If the csh alias references "parameters" (\!:1, \!* etc.),
>      then in zsh you need a function (referencing $1, $* etc.).
>      In recent versions of zsh this can be done by defining an anonymous
>      function within the alias.  Otherwise, a simple zsh alias suffices.
> 
> 2. ) If you use a zsh function, you need to refer _at_least_ to
>      $* in the body (inside the { }).  Parameters don't magically
>      appear inside the { } the way they get appended to an alias.
> --- 8< ---
> 
> That is, most paragraphs get a hanging left indent (outdent?), but not
> all do.  This happens in other sections, not just the one touched in
> the patch.  I'm not sure the hanging leader is even intentional.  Do
> others see this?

You mean the additional indentation of the "1."?  I see it both with and
without the patch:

[[[
--- Etc/FAQ.unpatched
+++ Etc/FAQ.patched
@@ -640,21 +640,22 @@
   (which converts your home directory to a ~).  In fact, this problem is
   better solved by defining the special function chpwd() (see
   the manual). Note also that the `;' at the end of the function is
   optional in zsh, but not in ksh or sh (for sh's where it exists).
 
 Here is Bart Schaefer's guide to converting csh aliases for zsh.
 
 
   1. ) If the csh alias references "parameters" (\!:1, \!* etc.),
      then in zsh you need a function (referencing $1, $* etc.).
-     Otherwise, you can use a zsh alias.
+     In recent versions of zsh this can be done by defining an anonymous
+     function within the alias.  Otherwise, a simple zsh alias suffices.
 
 2. ) If you use a zsh function, you need to refer _at_least_ to
      $* in the body (inside the { }).  Parameters don't magically
      appear inside the { } the way they get appended to an alias.
 
 3. ) If the csh alias references its own name (alias rm "rm -i"),
      then in a zsh function you need the "command" or "builtin" keyword
      (function rm() { command rm -i "$@" }), but in a zsh alias
      you don't (alias rm="rm -i").
 
@@ -683,44 +684,43 @@
      \!^-          $*[1,$#-1]
      \!*:q         "$@"
      \!*:x         $=*             ($*:x doesn't work (yet))
         
 
 6. ) Remember that it is NOT a syntax error in a zsh function to
      refer to a position ($1, $2, etc.) greater than the number of
      parameters. (E.g., in a csh alias, a reference to \!:5 will
      cause an error if 4 or fewer arguments are given; in a zsh
      function, $5 is the empty string if there are 4 or fewer
-     parameters.)
+     parameters.  Force an error in this example by using ${5?}.)
 
 7. ) To begin a zsh alias with a - (dash, hyphen) character, use
      `alias --':
       
              csh                            zsh
         ===============             ==================
         alias - "fg %-"             alias -- -="fg %-"
       
 
 8. ) Stay away from `alias -g' in zsh until you REALLY know what
      you're doing.
   
 
 There is one other serious problem with aliases: consider
   
     alias l='/bin/ls -F'
     l() { /bin/ls -la "$@" | more }
   
   `l' in the function definition is in command position and is expanded
   as an alias, defining `/bin/ls' and `-F' as functions which call
-  `/bin/ls', which gets a bit recursive.  This can be avoided if you use
-  `function' to define a function, which doesn't expand aliases.  It is
-  possible to argue for extra warnings somewhere in this mess.
+  `/bin/ls', which gets a bit recursive.  Recent versions of zsh treat
+  this as an error, but older versions silently create the functions.
 
 One workaround for this is to use the "function" keyword instead:
   
     alias l='/bin/ls -F'
     function l { /bin/ls -la "$@" | more }
   
   The `l' after `function' is not expanded.  Note you don't need
   the `()' in this case, although it's harmless.
 
 You need to be careful if you are defining a function with multiple
]]]

Adding a blank line between «enumeration(» and «myeit()» fixes it:

[[[
--- Etc/FAQ.unpatched
+++ Etc/FAQ.patched
@@ -637,22 +637,21 @@
   
     cd() { builtin cd "$@"; print -D $PWD; }
   
   (which converts your home directory to a ~).  In fact, this problem is
   better solved by defining the special function chpwd() (see
   the manual). Note also that the `;' at the end of the function is
   optional in zsh, but not in ksh or sh (for sh's where it exists).
 
 Here is Bart Schaefer's guide to converting csh aliases for zsh.
 
-
-  1. ) If the csh alias references "parameters" (\!:1, \!* etc.),
+1. ) If the csh alias references "parameters" (\!:1, \!* etc.),
      then in zsh you need a function (referencing $1, $* etc.).
      Otherwise, you can use a zsh alias.
 
 2. ) If you use a zsh function, you need to refer _at_least_ to
      $* in the body (inside the { }).  Parameters don't magically
      appear inside the { } the way they get appended to an alias.
 
 3. ) If the csh alias references its own name (alias rm "rm -i"),
      then in a zsh function you need the "command" or "builtin" keyword
      (function rm() { command rm -i "$@" }), but in a zsh alias
]]]


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

* Re: [PATCH] FAQ update for aliasing
  2021-02-01 16:13 ` Daniel Shahaf
@ 2021-02-01 20:11   ` Bart Schaefer
  2021-02-03 11:15     ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2021-02-01 20:11 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh hackers list

On Mon, Feb 1, 2021 at 8:14 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> > That is, most paragraphs get a hanging left indent (outdent?), but not
> > all do.  This happens in other sections, not just the one touched in
> > the patch.  I'm not sure the hanging leader is even intentional.  Do
> > others see this?
>
> You mean the additional indentation of the "1."?

No, I mean the LACK OF indentation on "2." and "3." and in fact on the
first line of ALMOST every paragraph in the document (that isn't a
section header).


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

* Re: [PATCH] FAQ update for aliasing
  2021-02-01 20:11   ` Bart Schaefer
@ 2021-02-03 11:15     ` Daniel Shahaf
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2021-02-03 11:15 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Mon, Feb 01, 2021 at 12:11:10 -0800:
> On Mon, Feb 1, 2021 at 8:14 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >
> > > That is, most paragraphs get a hanging left indent (outdent?), but not
> > > all do.  This happens in other sections, not just the one touched in
> > > the patch.  I'm not sure the hanging leader is even intentional.  Do
> > > others see this?
> >
> > You mean the additional indentation of the "1."?
> 
> No, I mean the LACK OF indentation on "2." and "3." and in fact on the
> first line of ALMOST every paragraph in the document (that isn't a
> section header).

That seems to be yodl2txt(1)'s default behaviour:

% print -rC1 '  hello' '  world' '' '  lorem' > 1.yo
% yodl2txt 1.yo
Yodl2html 4.02.00
No post-processing required for this txt conversion
% nl -ba < 1.txt
     1  hello
     2    world
     3
     4  lorem

The spaces in '  hello' were elided by something-or-other, while those in
'  world' were preserved literally.

Cheers,

Daniel


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

end of thread, other threads:[~2021-02-03 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 19:35 [PATCH] FAQ update for aliasing Bart Schaefer
2021-02-01 16:13 ` Daniel Shahaf
2021-02-01 20:11   ` Bart Schaefer
2021-02-03 11:15     ` Daniel Shahaf

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git