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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22659 invoked from network); 27 Nov 2021 17:48:21 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Nov 2021 17:48:21 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1638035301; b=Zb4kyvtGVLE44LrjZC3NcpQjtavV1++rAjmrc2WVyBL4ANFDYDRx9kxe2MvTE9bFnFosa70JRW 0OAwspK/oesSLATxC2CZ+a5SmnxM1SacxAbZuJlaz+GXx9Kiw0IFubfkeHPV5wPd/MIS0bkI/p maiBXOYvIcvNyqQvQ/ri5li7hfPzpz5fCwbyfvYku0zV/lHCrCIjo1dV5lWZJiZ+PkR7wApdfK 2EwvpdgOzTYslEWA1ELpZCRNS2j6vLgvLnZL4WKjrXOAaK74nxo3uWrKrU+tmR2rESJX+M9ZUt xy0GZQa/M/GPxp3PXD0K5L5G/8taO6VBgpUcRXZY9zLj8Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f179.google.com) smtp.remote-ip=209.85.219.179; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1638035301; bh=y+L/gLPcKT3LSNr9DYRobVJ4j2sqnBoPH1ROpxiGjvw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=psPc2AiU5xtO7GSHPIyDdQlA4lWyOC44QIZ13C370vAgS8306AHCkh7a4nhMwSoDfOtj+gGhdD TS+I4f5noW8ZhhJ8Euudf65EVotSnVDLutTeECKPJ0hP2WmjnQmpkM5/7oEYArKDJs34x7wghj 6oHJS5KZld4N2Xo6vVSy/vf3+t71eff6oDNWczwOcnByWFlLHPmz4VHaVsQGmdB1BH21lBVr64 BlM6thmXt2JMgONUV52i/qxz0h+gnCizDH2ASeJhJHdLCzZrLCiufc8Em8kOglic9YTNMg1SvY q4nODVGelrCuZgb1hlwMDYBEEWWmu29cfB/+I+6DXL8I7Q==; 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:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=7F9DKQwWY+jw0+Z6ULaUh6w+7cabOMDq8U57VRCw/Jo=; b=ACpeyZGnur/EH3owp6kR//fy56 yiAZ3UvBoEX079otnAeRx8wV+Jr3lu3ezzH9Lv88n6T5JMVfYuPE0b1PZIVpON/iy5MZMlPdIpbOk C7S7ZVaDpblQgewCcfVVhlyFru3wDCSfkBRBIz9jDQ5WgE4MSxNeYmJGXyhYVFC/pQM8lafMRX3FC XhU4cPo6elwlJAC1uJI8DfB67qm9YeJkbitkXf5A9BRWojJEOLG+JTcEN7UM139oetPItaaOkHQst CxQ24UH1HLSzVypgLMNyC8h2/Z+firNN/T7pPskkVaUyeS87JNkXYzOPo3g+fRp6HAfSir1Z+Eq5R 0F/WkYmA==; Received: from authenticated user by zero.zsh.org with local id 1mr1oB-000GMs-VE; Sat, 27 Nov 2021 17:48:20 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f179.google.com) smtp.remote-ip=209.85.219.179; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f179.google.com ([209.85.219.179]:33375) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mr1nT-000Fgw-Mb; Sat, 27 Nov 2021 17:47:36 +0000 Received: by mail-yb1-f179.google.com with SMTP id v7so29130999ybq.0 for ; Sat, 27 Nov 2021 09:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7F9DKQwWY+jw0+Z6ULaUh6w+7cabOMDq8U57VRCw/Jo=; b=WuAjDezyGafs6iLB+iTYgZmyh1v702DIbEHeg/Z8aV3qaGPyftpzosh5MUkTEOYbq1 PkaouMjAqF4tOVjyZHTXSLDjdLUZH++YQv/UaHJxb0OG3tZztG69U9CHbOxYMPOADV4E PcxEATvEEim6pHRQ1C7QS5ho7gZko1d4cStRuknu0T93TrvtiUqT5zdXvqLR4P4+z++x PEAdENF/e1MEI99HqC/hllWPK7f5vEm510E0VKR0WdoG3TMxaYNGPfqhWSRVkKOwUowg CrjYxDt6d/JhUoc4NdfoSCkJ1JXyXwwSUdmYaoxksEp5Jy2lwfHMKf+it+QlWIiE1EuQ iVTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7F9DKQwWY+jw0+Z6ULaUh6w+7cabOMDq8U57VRCw/Jo=; b=i+aGKFfSNRiHWM91q1yFg0AaX8CKjsIP2G5kxLK8lBGdsVXXT9wn+6eUtD91uKZUMF Z7gemjA3cJCJCdvYf+5qlBKOIQMIVLL4DuOna6Qcm7n9ech6MI9wRUOs5nbEUPzrkQro kFEEK6nuRYHP1E992O7TRsdtBAmGKsPMxWTG1yZp+5X8YLk88D5Kasd6uiWp3+06FsXe E8VqR6LyocYt89F8ogGlpKle6k1tlOpiiKRBg6nqLiVlJOFfxUTcjDbXu21P3VPbAmZp ROqZCz/xt95Zr20XFqQsYypJXF+1J68vvMDhvLEFMUAewC2AQ2U7t7FIRFiYykbNhOlm UW+Q== X-Gm-Message-State: AOAM530/Jq1tZLMGxJJ11QrqWdqzF6rbgVkadzg7WL6GMC8m3M11yh/o lwnkxXE3XhidPs3DF3W8JKoJr+CuwIrSMfeSPqt8wg== X-Google-Smtp-Source: ABdhPJxjhVRe2rj7jNURm22YDROCrdHe+YRu4YOrBzbeL4HL2nz8oGh/9PjEzDDer40OpsOu1aPEAzcirWRAnHtrsW0= X-Received: by 2002:a5b:f50:: with SMTP id y16mr24548535ybr.159.1638035254269; Sat, 27 Nov 2021 09:47:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sat, 27 Nov 2021 09:47:23 -0800 Message-ID: Subject: Re: Source mangling in $functions_source and typeset -f To: Zach Riggle Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27370 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: On Sat, Nov 27, 2021 at 12:02 AM Zach Riggle wrote: > > 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 With the exception of the contents of strings (including here-documents), the original source of a function is not kept in shell memory. Instead a parse tree is stored and used to regenerate the function definition by "typeset -f" et al. Comments and semantically-meaningless whitespace are discarded during parsing, hence they're not available later. > 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)? The parse tree only tracks the line numbers of executable code, so as to be able to update the LINENO variable and print line numbers in debug traces and prompts. The line number of the closing brace isn't recorded (in fact it's possible to define a function without any open or close brace if the body is a single expression). So, strictly speaking, no, neither of those.