From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HOSTED_IMG_MULTI_PUB_01,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 915 invoked from network); 27 Nov 2021 08:02:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Nov 2021 08:02:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1638000169; b=QI8zXjmVRXN0t5ZZV9cQTFf9oYiVVrLB4zvl1M4hdV0TYWX4Xk3wWNutrry3VwF/tXHVxdgAZx jEliq1oiYGD9K6tYfswzyj1SDv6O2w67h2Spyu7AUbeP2rLkRxpcFX/VDng+xbcJh+MEkbg5Vg Te+vE0MfoIRqf0f7KSl/OrIsxmtF+l1LQpxecRAQc5Lw6e0H7yXQO7N2lo8GHvUKOOcmCG1Fj+ B51MzV1pQotwooCjfW9KQO1zGbmJQ//wPuR9r6DSjVo5h2mHM/Ugugx/h0XV0ODA3sYYooSd9K etZY2OkGjk2tz7pgQqYQUkNYf61UFDblPbSNeECFvhOYtQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1638000169; bh=BkELi2e1fUbknjvn3ag7sFUws4EsnnJaI2py4qJPW0I=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=g9SY3OYZn+gnR1FHw3u/FXq3e0BbHHamnIhfQblSk9fzw3H1ifzJYn4aQvxw5TAZNioV85g1uA kpctqGTEJRGnTX2/HRSHYsauDvYoHoLUspXJucoUZgE91/TrZdpkwfi3d2wdt9GncsC+c+zOQI xlK9xSVlURy0svmsRCsVP7sHImNL5Vf0FwHEQVkydIQLKGBUjgJTGJgVH0NG4wW4CKDXfX6ts9 c8glf/W2f8I9oG/mxPaa1qdYR4NJ0TnfK03xtcl1EPfHYEU6ALU9JdciLsBRG/DOcCL7aC7YrR DzKcCJWkClsAdZ323a/TvlyxZgzpQw0LCedVIylajX+mpQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=cikAQQDKeEWLEHX3QWv+HBGe6d94/m5agKBnVaK7k+Q=; b=iw4ZLYIp2ScfQwcwrX0xASbWTm 3wJYlaK0zV3XqvAhv2DaqZ9f6z7tdASC7U4Tco5lFKrTQszW/z/mg1r62ynDKpzSQzHVXNayTqqaG eSnhLlGvasg7rYyuAYXTBTdBgzBbWtyb5OLsQybQlPuAtv4OBchBpi/jBONL92TOqLcv/9hTNIMyO IG7y0ETtR+zzQxFLa1FQxKmXwscPGmz3GL9FbdCesp9JvW6HnP8qIe8MEnTYi0av80LJrJ1fmlyBz iVorLGo8gbHo830X02jCTY1O+HY7ppl8/r9z1V8nwWn7P5wOUW/MEIAxjzw8C2XtAnUyAdJWhpZEg +nYiSbhA==; Received: from authenticated user by zero.zsh.org with local id 1mqsfY-0000FP-7x; Sat, 27 Nov 2021 08:02:48 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f47.google.com ([209.85.221.47]:34696) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mqsef-000PY1-Ds; Sat, 27 Nov 2021 08:01:54 +0000 Received: by mail-wr1-f47.google.com with SMTP id j3so23654567wrp.1 for ; Sat, 27 Nov 2021 00:01:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=cikAQQDKeEWLEHX3QWv+HBGe6d94/m5agKBnVaK7k+Q=; b=PsksciW19ZxnT2HBOCwr1ZefOJvzn+wPsWXdIeHIPKorPq/gWufSxEFrBFoIqhL2SV J7bHhoDlmDcdUq8JS0ARchII5lHiWWc0MudD/FSSp0WtV2SQ2mX3hPo6Af044OeZE9Ul jOUdxNk0tXvqk76dc45nJ7ne13n3m/iKqKKY8r0kUNOeN7mKIPxurfkFydfz8lUHMGRZ XieyHNlR6s0rllSGCzVcge/30PsxE5r1L0Vd3eVr2u5cNWApM8k143zBy60pgqBaKzjf CvjLLR5RR8TENrCL/ekujacLxtbeDGal9PTYft5xRy1xoVnw/3XjUSfvAqJLKO53ne4r qIiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=cikAQQDKeEWLEHX3QWv+HBGe6d94/m5agKBnVaK7k+Q=; b=5FF7YANG5PM4IQRNRnPOx+3f4aQm9lPHFXutrvAO3fZU1X9TH7++IurKRLmtEpVof/ 9oMmJoYHT9x/MhzBItNC74ngLVbq2eJRePEB0EY/aOj6zML0GMT+POVTjwsFpN3XBaHW mGSOK0PUxNa7jF50y7Slo7wQ1WInhsevgkgzv8sbzdCSs/9Xdzkg1rRdnVgUUtaDzsg9 yUE80am0hSee9Ar+kmuoCkN0PTZwQtUZ9J37rO8lhiQbGg/GDcgJY3d17mLdOXW3R/xG c6rshogj2HSDPLEnPpERG1XjKv2rgOaWmKLnsvT/y8YJgE3GPKA4OdQRcz4TS4B9SEHL i+oQ== X-Gm-Message-State: AOAM532heBrmIQ+VTSJRSfhU6EPuiNLqc26IbyxoWSB85pSvmH+3Rlir bO9ZuC96L23noCsPIAmravPb2KdzNF/ksROXHcZ7wvCIYrvFmA== X-Google-Smtp-Source: ABdhPJxt7ZHN9pPIALaC1Xh7pG/S+6NbtQSMJDaPAqcRmDi3mgOENe+ajEsrZK8y+7tQyafZUDDb0/iocwUEIC/WKr8= X-Received: by 2002:a5d:4b45:: with SMTP id w5mr19441932wrs.272.1638000112653; Sat, 27 Nov 2021 00:01:52 -0800 (PST) MIME-Version: 1.0 From: Zach Riggle Date: Sat, 27 Nov 2021 02:01:41 -0600 Message-ID: Subject: Source mangling in $functions_source and typeset -f To: Zsh Users Content-Type: multipart/alternative; boundary="000000000000db5bd705d1c09e33" X-Seq: 27367 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --000000000000db5bd705d1c09e33 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello again! I've been playing around with some things regarding $fpath and autoloadable functions. Ultimately, I've got a nice wrapper which will print out the source of a function (and autoload it if necessary) and then pass it to `bat` for syntax highlighting. Unfortunately, "$functions_source[foo]" and "typeset -f foo" both seem to remove all comments, and rewrite the source such that there's no empty newlines -- even if done explicitly with line-continuation slashes, or if spaced out manually and meticulously in an array. With a little bit of grep-foo, it's possible to use "$functions[foo]" and search for the file for the function declaration. With this little trick, it makes it easy to open the editor to the correct line in the file where the function is declared. This makes it easy to display the path/to/file:linenum on which a given function is declared, and open it easily in the editor of your choice with a =E2=8C=98-Click or =E2=8C=83-Click depending on your chosen editor. https://i.imgur.com/oPSiPWB.png However, there's no easy way to determine the LAST line in the original file which corresponds to the function -- due to aforementioned newline- and comment-stripping. https://i.imgur.com/nvzuFEm.png Is there a convenient way, from within zsh, to get either: - The original, unmodified source of a function (autoloaded or otherwise= ) - The line offsets in the file where the function is defined (if any)? Getting the starting offset is easy-ish (thanks grep!) but finding the function end is less easy. I expect there are Zsh internals that could track this if desired, but it simply isn't tracked. Are there any easy fixes to this? My best path forward for detecting the [start, end] of a function, with its original comments, will rely on finding a closing '}' with the same indentation as the 'function foo()' definition. *Zach Riggle* --000000000000db5bd705d1c09e33 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello again!

I've been playin= g around with some things regarding $fpath and autoloadable functions.
=
Ultimately, I've got a nice wrapper which will print out= the source of a function (and autoload it if necessary) and then pass it t= o `bat` for syntax highlighting.

Unfortunately, &q= uot;$functions_source[foo]" and "typeset -f foo" both seem t= o remove all comments, and rewrite the source such that there's no empt= y newlines -- even if done explicitly with line-continuation slashes, or if= spaced out manually and meticulously=C2=A0in an array.

With a little bit of grep-foo, it's possible to use "$functi= ons[foo]" and search for the file for the function declaration.=C2=A0 = With this little trick, it makes it easy to open the editor to the correct = line in the file where the function is declared.

T= his makes it easy to display the path/to/file:linenum on which a given func= tion is declared, and open it easily in the editor of your choice with a = =E2=8C=98-Click or =E2=8C=83-Click depending on your chosen editor.


However, t= here's no easy way to determine the LAST line in the original file whic= h corresponds to the function -- due to aforementioned newline- and comment= -stripping.

Is there a convenient way, from within zsh, to get either:
  • The original, unmodified source of a function (autoloaded or = otherwise)
  • The line offsets in the file where the function is defin= ed (if any)?
Getting the starting offset is easy-ish (thanks = grep!) but finding the function end is less easy.=C2=A0 I expect there are = Zsh internals that could track this if desired, but it simply isn't tra= cked.

Are there any easy fixes to this?=C2=A0 My b= est path forward for detecting the [start, end] of a function, with its ori= ginal comments, will rely on finding a closing '}' with the same in= dentation as the 'function foo()' definition.

Zach Riggle

--000000000000db5bd705d1c09e33--