From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Automatically adding local variables to tangled file Date: Thu, 06 Jun 2013 10:01:25 -0600 Message-ID: <87ehcf6xey.fsf@gmail.com> References: <878v2omz5g.fsf@krugs.de> <51af4bfd.0c95ec0a.2372.097e@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukcdm-0004qj-5e for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 12:02:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ukcdk-0006Vn-2O for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 12:02:17 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:47022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukcdj-0006VA-Pr for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 12:02:16 -0400 Received: by mail-pa0-f44.google.com with SMTP id wp1so1843601pac.31 for ; Thu, 06 Jun 2013 09:02:15 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Darlan Cavalcante Moreira Cc: Rainer M Krug , emacs-orgmode , Vitalie Spinu > It's a good idea to have useful information in the tangled file that can > help these functions. But since org-mode can already tangle with comments > containing useful information, isn't this enough to detect that the file > is a tangled file? > I personally prefer the solution shown below of adding a file-local variable using the post-tangle hook. As mentioned previously this makes the detection of tangled code much faster, simpler and less error prone than grepping the file for comments. > > On the other hand, a local variable in the tangled files to set the buffer > to read-only could be very useful to avoid the mistake of editing the > tangled files directly. > We already set the permission of tangled files to be executable when they include a shebang line. Perhaps we could add an option (or change the default) to set the permissions of tangled files to be read only. Perhaps this could be done using the post-tangle hook with something like the following. ;; -*- emacs-lisp -*- (defun org-babel-mark-tangled-as-read-only () "Mark the current file read only. If it is executable keep it executable." (if (= #o755 (file-modes (buffer-file-name))) (set-file-modes (buffer-file-name) #o555) (set-file-modes (buffer-file-name) #o444))) (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-tangled-as-read-only) >> >> Therefore my question: >> >> Would it be possible and reasonable, to add a local variable to each >> tangled file which identifies the file as an file tangled from an org >> mode file? >> >> He added the following to his config file to test the approach: >> >> ,---- >> | (defvar org-babel-tangled-file nil >> | "If non-nill, current file was tangled with org-babel-tangle") >> | (put 'org-babel-tangled-file 'safe-local-variable 'booleanp) >> | >> | (defun org-babel-mark-file-as-tangled () >> | (add-file-local-variable 'org-babel-tangled-file t) >> | (basic-save-buffer)) >> | >> | (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tangled) >> `---- >> I think the above code should be considered an implementation rather than simply a test. This is exactly what the post-tangle hook is intended to support. Is there a motivating reason for this behavior to be "built in"? >> >> and he also already added automatic redirection to the org mode file >> via org-babel-tangle-jump-to-org to ESS on SVN. >> >> To keep backwards compatibility, a variable >> org-babel-tangle-add-tangled-file-variable could be introduced, which >> can have the following values: >> >> - nil :: (default) do not add anything >> - t :: org-babel-tangled-file is added as t to the tangled files >> - "name" :: org-babel-tangled-file is set to the org file name >> - "path" :: org-babel-tangled-file is set to the path of the org file >> - "all" :: org-babel-tangled-file is set to the full name including path >> of the org file >> >> I can even imagine many more possibilities for the use of local file >> variables to store meta data in the tangled file (VCS info comes to >> mind, which would enable one to even go back to older revisions based on >> the tangled code rather easily). >> I agree that local-file variables show much promise, although I think (at least for now) the best way to set such variables is through the post-tangle-hook as Vitalie has already done. Best, >> >> Cheers, >> >> Rainer >> >> -- >> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) >> >> Centre of Excellence for Invasion Biology >> Stellenbosch University >> South Africa >> >> Tel : +33 - (0)9 53 10 27 44 >> Cell: +33 - (0)6 85 62 59 98 >> Fax : +33 - (0)9 58 10 27 44 >> >> Fax (D): +49 - (0)3 21 21 25 22 44 >> >> email: Rainer@krugs.de >> >> Skype: RMkrug -- Eric Schulte http://cs.unm.edu/~eschulte