From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 8D0DFbsAVmFa5gAAgWs5BA (envelope-from ) for ; Thu, 30 Sep 2021 20:23:55 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id cOvKELsAVmGRUAAA1q6Kng (envelope-from ) for ; Thu, 30 Sep 2021 18:23:55 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C99A428C51 for ; Thu, 30 Sep 2021 20:23:52 +0200 (CEST) Received: from localhost ([::1]:33738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW0il-0001db-Ry for larch@yhetil.org; Thu, 30 Sep 2021 14:23:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW0i6-0001dI-Od for emacs-orgmode@gnu.org; Thu, 30 Sep 2021 14:23:11 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:39799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mW0i4-0005I4-8w for emacs-orgmode@gnu.org; Thu, 30 Sep 2021 14:23:10 -0400 Received: by mail-pl1-x62f.google.com with SMTP id c4so4644521pls.6 for ; Thu, 30 Sep 2021 11:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:user-agent:message-id:mime-version; bh=yAw4s5dcFj7ScumetmXxnbfQI/VFAK5V02v9d4uPqHw=; b=fmjdaNmEfyTMybaC2swq+SEFfdVknwSyUr61/vZOIntOuun4fwcpQpMcl2JuiBgMdC d8gX8wPzU3Ezn5BV5wo3xDd67SC74th9lGEx2SlqpYa+BASBTiPsryHrOkBHwUM48oBC 0HNyzNbPjKi+wI7opUcO7rPV4akkHMUW+04QuXbQHPno1ihEcqbgT2Uu1eCfHSSmX0go QuhSN/XcsdXQhyGsweT7hvfnHZd4uhxHBMMgbaLl2ueUWyjLgZHSQIDAPit0O/9H8Pwp 3iBpkKwHldSjj/3JphKbbV2wS8+AHlA5FVQUHCntZYPha38y64OdKWyACoj4rjyhUmg8 J6Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:user-agent:message-id :mime-version; bh=yAw4s5dcFj7ScumetmXxnbfQI/VFAK5V02v9d4uPqHw=; b=jZ67Ht37ddLOjQqDtWeR6RnYLCKD+zaZV8v+0MDNWe+LgZolbjXMH4impeo0W82ulj wp/2j0Ss5BrqOaG6hAmf2Q5+IFppttVnJJBgAcMJGx6+QmijWBCuNjXlp8I0uP4iuRMs RIYFG8bsN/azzX690B4AkIIpUtNxaKvXRqNkUrFYzwScGKb4chxF0Pf1/P93can967vh 7qwmQow8cbdESKyOtE4iNn6guWCILzTwyiIP0yVCjzPrSbBil+7lQogaWyDkDzogyg/2 15BL65KJwiyJOLyZwDcc0uTwIe8QHSYlZK/6AcRPAx+gfbwCDWk8j8h6YpNJmzsfwIdA DKwA== X-Gm-Message-State: AOAM5300BRI+FSewwqG0M2jT9du0nMn5mQrrKFtmG2TkMQkA48kxqT+Q d/ZSosjXSm8w+n1mWeKMxqwwCICYhqc= X-Google-Smtp-Source: ABdhPJwAvIp4ZNcRvxF4yPzPM9YPC0YdoSWgGiutECOThDg517tGuaoRq+F2T68HgNGmwHIPQTYGsQ== X-Received: by 2002:a17:90a:5583:: with SMTP id c3mr7895727pji.133.1633026186210; Thu, 30 Sep 2021 11:23:06 -0700 (PDT) Received: from localhost (61-245-128-160.3df580.per.nbn.aussiebb.net. [61.245.128.160]) by smtp.gmail.com with ESMTPSA id q21sm3505396pgk.71.2021.09.30.11.23.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 11:23:05 -0700 (PDT) From: Timothy To: Org Mode List Subject: [PATCH] Accept more :tangle-mode specification forms Date: Fri, 01 Oct 2021 02:14:55 +0800 User-agent: mu4e 1.6.5; emacs 28.0.50 Message-ID: <875yuh9b3t.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=tecosaur@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633026235; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=yAw4s5dcFj7ScumetmXxnbfQI/VFAK5V02v9d4uPqHw=; b=XQk+/B0p5qa4f4wCBpLjKAof0Z0wzzksJKPrpwO2d2DeD1VIUPDVlYaph3fvuNA2YWV9OP W19//eNydjdMgvZwGAn8nqzzIB0fyUsNZeUkDzm6gDyCyCnhvR1+V2bgY2Ddjo/n/7vvAK YhYMBK9G7Qx2TiQS6fVLsJvpNQIrt29sIGzp4hBX6MiJUbJpN7q3LUJji0Jr/+C5meqX+t +HzUA42FTF8a8J/MHRr6Fgz8msaYsxk++kFrGDhKpjfl/iuzhOlBTb4wetUsJ2QG8mufmZ 3Qd/tVzPVzV1ygIoufKnabj9NbmGl3RfKu2dnAaptT6PiuFu4v1xsfnFSwH+VQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633026235; a=rsa-sha256; cv=none; b=X32RKuuBeZFRfKyjajd8fTnYQUhKBlA1/zT4mebb00m+fOCnxiga+ghwXTjOBcTKXNDWfc PQ426+7Xag44nwiiIpgKQYuVOM4FbwSMJhcmIwhOD96fq9Y+3O6sLeKpILEW73bSW182zH b2ipKBlYojFLlMrzi84Y5rwEBMSIE4VxvUmCCjEooWAQ4ie73Bxk9p/4mu46nMFIWZLpC9 ZuM9OeRQUQcEbSOmgeysht2MU0PAZo5OKj042xDhl+tBbTwvSya3zDYQHH8upBVxPGWD3o ICgbrXgw75uV3f2lv0YKZQ3EqywB2Quh280LPI1krX//E9YweHz/SA5acIFA8g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fmjdaNmE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -4.00 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fmjdaNmE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: C99A428C51 X-Spam-Score: -4.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: kwFzhM33le1d --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, Currently, the only way to set a file mode when tangling seems to be=20 :tangle-mode (identity #o755) In a [prior thread], Jeremy proposed that :tangle-mode should convert octal number strings to the required decimal form. I think we should go further, = and so have prepared the attached patch based on a snippet I shared in the thre= ad. To quote the docstring of the new function I=E2=80=99m introducing, this pa= tch now accepts the following :tangle-mode forms: =E2=80=A2 an integer (returned without modification) =E2=80=A2 =E2=80=9C#o755=E2=80=9D (elisp-style octal) =E2=80=A2 =E2=80=9C0755=E2=80=9D (c style octal) =E2=80=A2 =E2=80=9C755=E2=80=9D (chmod style octal) =E2=80=A2 =E2=80=9Crwxrw-r=E2=80=93=E2=80=9D (ls style specification) =E2=80=A2 =E2=80=9Ca=3Drw,u+x=E2=80=9D (chmod style) =E2=80=A2 =E2=80=9Crwx=E2=80=9D (interpreted as =E2=80=9Cu=3Drwx=E2=80=9D) Why be so permissive? I=E2=80=99d refer you to my reasoning in the prior th= read: I think there are a few arguably =E2=80=9Csensible=E2=80=9D formats that a = user could reasonably assume, and if we can support most of them without introducing ambiguity in parsing or interpretation (and I think we can), can=E2=80=99t we make every= one happy? All the best, Timothy [prior thread] --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-tangle-Accept-more-tangle-mode-forms.patch >From 5087de0d70151c33d66eb13dda84d78a361d7053 Mon Sep 17 00:00:00 2001 From: TEC Date: Fri, 1 Oct 2021 02:02:22 +0800 Subject: [PATCH] ob-tangle: Accept more :tangle-mode forms * lisp/ob-tangle.el (org-babel-tangle): Accept many more forms for :tangle-mode, including octal strings (#o755, 0755, 755), ls forms (rwx, rw-r--r--), and chmod forms (a=rw,u+x). The interpretation of the input is now handled by the new function `org-babel-interpret-file-mode' which references the new variable `org-babel-tangle-default-mode' when considering relative mode forms. --- lisp/ob-tangle.el | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 2dd1d031c..28a235429 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -140,6 +140,14 @@ (defcustom org-babel-process-comment-text 'org-remove-indentation :version "24.1" :type 'function) +(defcustom org-babel-tangle-default-mode #o544 + "The default mode used for tangled files, as an integer. +The default value 356 correspands to the octal #o544, which is +read-write permissions for the user, read-only for everyone else." + :group 'org-babel + :version "9.6" + :type 'integer) + (defun org-babel-find-file-noselect-refresh (file) "Find file ensuring that the latest changes on disk are represented in the file." @@ -255,7 +263,7 @@ (defun org-babel-tangle (&optional arg target-file lang-re) (when she-bang (unless tangle-mode (setq tangle-mode #o755))) (when tangle-mode - (add-to-list 'modes tangle-mode)) + (add-to-list 'modes (org-babel-interpret-file-mode tangle-mode))) ;; Possibly create the parent directories for file. (let ((m (funcall get-spec :mkdirp))) (and m fnd (not (string= m "no")) @@ -298,6 +306,38 @@ (defun org-babel-tangle (&optional arg target-file lang-re) path-collector)) path-collector)))) +(defun org-babel-interpret-file-mode (mode) + "Determine the integer representation of a file MODE specification. +The following forms are currently recognised: +- an integer (returned without modification) +- \"#o755\" (elisp-style octal) +- \"0755\" (c style octal) +- \"755\" (chmod style octal) +- \"rwxrw-r--\" (ls style specification) +- \"a=rw,u+x\" (chmod style) * +- \"rwx\" (interpreted as \"u=rwx\") * + +* The interpretation of these forms relies on `file-modes-symbolic-to-number', + and uses `org-babel-tangle-default-mode' as the base mode." + (cond + ((integerp mode) mode) + ((not (stringp mode)) + (error "File mode %S not recognised as a valid format." mode)) + ((string-match-p "^0?[0-7][0-7][0-7]$" mode) + (string-to-number mode 8)) + ((string-match-p "^#o[0-7][0-7][0-7]$" mode) + (string-to-number (substring mode 2) 8)) + ((string-match-p "^[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\(,[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\)*$" mode) + (file-modes-symbolic-to-number mode org-babel-tangle-default-mode)) + ((string-match-p "^[rwx-]\\{3\\}$" mode) + (file-modes-symbolic-to-number (concat "u=" mode) org-babel-tangle-default-mode)) + ((string-match-p "^[rwx-]\\{9\\}$" mode) + (file-modes-symbolic-to-number (concat "u=" (substring mode 0 3) + ",g=" (substring mode 3 6) + ",a=" (substring mode 6 9)) + 0)) + (t (error "File mode %S not recognised as a valid format." mode)))) + (defun org-babel-tangle-clean () "Remove comments inserted by `org-babel-tangle'. Call this function inside of a source-code file generated by -- 2.33.0 --=-=-=--