[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Treat :tangle-mode as an octal value not integer
From: |
Timothy |
Subject: |
Re: [PATCH] Treat :tangle-mode as an octal value not integer |
Date: |
Wed, 29 Sep 2021 22:58:43 +0800 |
User-agent: |
mu4e 1.6.5; emacs 28.0.50 |
<tomas@tuxteam.de> writes:
> So you favour going the "full custom special parser". You're much more
> involved in Org, so I think your gut feeling counts more than mine here :)
Well, I'm not sure that my feeling is representative of experienced Org users,
my opinion basically boils down to:
>> I think as long as it’s clear what’s intended, and it’s not some home-baked
>> non-standard format, or terribly annoying to support — why not?
Rephrased: I think there are a few arguably "sensible" 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't we make
everyone happy?
> `755' is the funniest one, since, strictly speaking it doesn't correspond
> to anything "out there" (note that the shell command `chmod' wants the
> leading zero, or, well, it will do surprising things if you don't
> provide it ;-)
Consider my suggestion amended to 0755 etc. :)
Anyway, as an example here's a code snippet that implements everything I've
mentioned.
#+begin_src emacs-lisp
(defvar org-tangle-default-mode #o544
"The default mode for tangled files, as an integer.")
(defun org-interpret-file-mode (mode)
(cond
((integerp mode) mode)
((not (stringp mode))
(user-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 0))
((string-match-p "^[rwx-]\\{3\\}$" mode)
(file-modes-symbolic-to-number (concat "u=" mode) org-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))
org-tangle-default-mode))
(t (user-error "File mode %S not recognised as a valid format." mode))))
#+end_src
--
Timothy
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, (continued)
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, tomas, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, dkrm, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, tomas, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, Gyro Funch, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, tomas, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, Jeremy Cowgar, 2021/09/29
- Re: [PATCH] Treat :tangle-mode as an octal value not integer, tomas, 2021/09/29
Re: [PATCH] Treat :tangle-mode as an octal value not integer, Bastien, 2021/09/29
Re: [PATCH] Treat :tangle-mode as an octal value not integer, Timothy, 2021/09/29
Re: [PATCH] Treat :tangle-mode as an octal value not integer, Greg Minshall, 2021/09/29
Re: [PATCH] Treat :tangle-mode as an octal value not integer, tomas, 2021/09/29