emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Wrong comment character when adding file local variables?
@ 2013-06-07 13:12 Rainer M Krug
  2013-06-07 13:48 ` Vitalie Spinu
  0 siblings, 1 reply; 8+ messages in thread
From: Rainer M Krug @ 2013-06-07 13:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2386 bytes --]

Hi

when tangling the following file

,----
| * Package Files
| ** DESCRIPTION File
| :PROPERTIES:
| :tangle:   ./DESCRIPTION
| :shebang:  
| :padline: no
| :no-expand: TRUE
| :comments: no
| :END:
| #+begin_src R
|   Package: asmDrak
| #+end_src
| 
| ** NAMESPACE File
| :PROPERTIES:
| :tangle:   ./NAMESPACE
| :shebang:  
| :padline: no
| :no-expand: TRUE
| :comments: no
| :END:
| #+begin_src R
|  this is a test
| #+end_src
| 
| 
| ** DESC2 File
| :PROPERTIES:
| :tangle:   ./DESC2
| :shebang:  
| :padline: no
| :no-expand: TRUE
| :comments: yes
| :END:
| #+begin_src R
|   this is a test
| #+end_src
`----

I get the following tangled files:

DESCRIPTION:

,----
| Package: asmDrak
| 
| ;; Local Variables:
| ;; org-babel-tangled-file: t
| ;; buffer-read-only: t
| ;; End:
`----

which has the wrong comment character (should have #)

NAMESPACE:

,----
| this is a test
| 
| ## Local Variables:
| ## org-babel-tangled-file: t
| ## buffer-read-only: t
| ## End:
`----

which has the correct comment characters, and 

DESC2

,----
| ## [[file:~/tmp/tangle.org::*DESC2%20File][DESC2\ File:1]]
| this is a test
| ## DESC2\ File:1 ends here
| 
| ;; Local Variables:
| ;; org-babel-tangled-file: t
| ;; buffer-read-only: t
| ;; End:
`----

which has the correct comment characters for the comments, but the wrong
ones for the file local variables.

I use the following in my .emacs file to set the post-tangle-hook to add
the local file variables:

,----
|   (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)
|     (add-file-local-variable 'buffer-read-only t)
|     ;; (add-file-local-variable 'eval: (auto-revert-mode))
|     (basic-save-buffer))
|   
|   (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tangled)
`----

I assume this is a bug somewhere?


Org-mode version 8.0.3 (release_8.0.3-211-gf16b53 @
/home/rkrug/.emacs.d/org-mode/lisp/)

GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.6.4)
 of 2013-04-14 on actinium, modified by Debian

Cheers,

Rainer

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-07 13:12 Wrong comment character when adding file local variables? Rainer M Krug
@ 2013-06-07 13:48 ` Vitalie Spinu
  2013-06-07 15:40   ` Rainer M Krug
  0 siblings, 1 reply; 8+ messages in thread
From: Vitalie Spinu @ 2013-06-07 13:48 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: emacs-orgmode


All your examples are placed in fundamental mode. The comments are
treated by org and thus are correct, local variables are inserted
according to the major mode.

I don't how this could be easily fixed on org side, but you can solve it
straightforwardly with:

   (add-to-list 'auto-mode-alist (cons "NAME\\|DESC" 'R-mode))

 Vitalie

 >> Rainer M Krug <Rainer@krugs.de>
 >> on Fri, 07 Jun 2013 15:12:58 +0200 wrote:

 > Hi

 > when tangling the following file

 > ,----
 > | * Package Files
 > | ** DESCRIPTION File
 > | :PROPERTIES:
 > | :tangle:   ./DESCRIPTION
 > | :shebang:  
 > | :padline: no
 > | :no-expand: TRUE
 > | :comments: no
 > | :END:
 > | #+begin_src R
 > |   Package: asmDrak
 > | #+end_src
 > | 
 > | ** NAMESPACE File
 > | :PROPERTIES:
 > | :tangle:   ./NAMESPACE
 > | :shebang:  
 > | :padline: no
 > | :no-expand: TRUE
 > | :comments: no
 > | :END:
 > | #+begin_src R
 > |  this is a test
 > | #+end_src
 > | 
 > | 
 > | ** DESC2 File
 > | :PROPERTIES:
 > | :tangle:   ./DESC2
 > | :shebang:  
 > | :padline: no
 > | :no-expand: TRUE
 > | :comments: yes
 > | :END:
 > | #+begin_src R
 > |   this is a test
 > | #+end_src
 > `----

 > I get the following tangled files:

 > DESCRIPTION:

 > ,----
 > | Package: asmDrak
 > | 
 > | ;; Local Variables:
 > | ;; org-babel-tangled-file: t
 > | ;; buffer-read-only: t
 > | ;; End:
 > `----

 > which has the wrong comment character (should have #)

 > NAMESPACE:

 > ,----
 > | this is a test
 > | 
 > | ## Local Variables:
 > | ## org-babel-tangled-file: t
 > | ## buffer-read-only: t
 > | ## End:
 > `----

 > which has the correct comment characters, and 

 > DESC2

 > ,----
 > | ## [[file:~/tmp/tangle.org::*DESC2%20File][DESC2\ File:1]]
 > | this is a test
 > | ## DESC2\ File:1 ends here
 > | 
 > | ;; Local Variables:
 > | ;; org-babel-tangled-file: t
 > | ;; buffer-read-only: t
 > | ;; End:
 > `----

 > which has the correct comment characters for the comments, but the wrong
 > ones for the file local variables.

 > I use the following in my .emacs file to set the post-tangle-hook to add
 > the local file variables:

 > ,----
 > |   (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)
 > |     (add-file-local-variable 'buffer-read-only t)
 > |     ;; (add-file-local-variable 'eval: (auto-revert-mode))
 > |     (basic-save-buffer))
 > |   
 > |   (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tangled)
 > `----

 > I assume this is a bug somewhere?

 > Org-mode version 8.0.3 (release_8.0.3-211-gf16b53 @
 > /home/rkrug/.emacs.d/org-mode/lisp/)

 > GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.6.4)
 >  of 2013-04-14 on actinium, modified by Debian

 > Cheers,

 > Rainer

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-07 13:48 ` Vitalie Spinu
@ 2013-06-07 15:40   ` Rainer M Krug
  2013-06-07 16:48     ` Vitalie Spinu
  2013-06-08  7:47     ` Nick Dokos
  0 siblings, 2 replies; 8+ messages in thread
From: Rainer M Krug @ 2013-06-07 15:40 UTC (permalink / raw)
  To: Vitalie Spinu; +Cc: Rainer M Krug, emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 3784 bytes --]

On Friday, June 7, 2013, Vitalie Spinu wrote:

>
> All your examples are placed in fundamental mode. The comments are
> treated by org and thus are correct, local variables are inserted
> according to the major mode.
>
> The question is why - all .R files are automatically in r mode when I open
them and all other R files tangle fine.


> I don't how this could be easily fixed on org side, but you can solve it
> straightforwardly with:
>
>    (add-to-list 'auto-mode-alist (cons "NAME\\|DESC" 'R-mode))


Ok - I'check it out on Monday.

Cheers and have a nice weekend,

Rainer

>
>  Vitalie
>
>  >> Rainer M Krug <Rainer@krugs.de <javascript:;>>
>  >> on Fri, 07 Jun 2013 15:12:58 +0200 wrote:
>
>  > Hi
>
>  > when tangling the following file
>
>  > ,----
>  > | * Package Files
>  > | ** DESCRIPTION File
>  > | :PROPERTIES:
>  > | :tangle:   ./DESCRIPTION
>  > | :shebang:
>  > | :padline: no
>  > | :no-expand: TRUE
>  > | :comments: no
>  > | :END:
>  > | #+begin_src R
>  > |   Package: asmDrak
>  > | #+end_src
>  > |
>  > | ** NAMESPACE File
>  > | :PROPERTIES:
>  > | :tangle:   ./NAMESPACE
>  > | :shebang:
>  > | :padline: no
>  > | :no-expand: TRUE
>  > | :comments: no
>  > | :END:
>  > | #+begin_src R
>  > |  this is a test
>  > | #+end_src
>  > |
>  > |
>  > | ** DESC2 File
>  > | :PROPERTIES:
>  > | :tangle:   ./DESC2
>  > | :shebang:
>  > | :padline: no
>  > | :no-expand: TRUE
>  > | :comments: yes
>  > | :END:
>  > | #+begin_src R
>  > |   this is a test
>  > | #+end_src
>  > `----
>
>  > I get the following tangled files:
>
>  > DESCRIPTION:
>
>  > ,----
>  > | Package: asmDrak
>  > |
>  > | ;; Local Variables:
>  > | ;; org-babel-tangled-file: t
>  > | ;; buffer-read-only: t
>  > | ;; End:
>  > `----
>
>  > which has the wrong comment character (should have #)
>
>  > NAMESPACE:
>
>  > ,----
>  > | this is a test
>  > |
>  > | ## Local Variables:
>  > | ## org-babel-tangled-file: t
>  > | ## buffer-read-only: t
>  > | ## End:
>  > `----
>
>  > which has the correct comment characters, and
>
>  > DESC2
>
>  > ,----
>  > | ## [[file:~/tmp/tangle.org::*DESC2%20File][DESC2\ File:1]]
>  > | this is a test
>  > | ## DESC2\ File:1 ends here
>  > |
>  > | ;; Local Variables:
>  > | ;; org-babel-tangled-file: t
>  > | ;; buffer-read-only: t
>  > | ;; End:
>  > `----
>
>  > which has the correct comment characters for the comments, but the wrong
>  > ones for the file local variables.
>
>  > I use the following in my .emacs file to set the post-tangle-hook to add
>  > the local file variables:
>
>  > ,----
>  > |   (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)
>  > |     (add-file-local-variable 'buffer-read-only t)
>  > |     ;; (add-file-local-variable 'eval: (auto-revert-mode))
>  > |     (basic-save-buffer))
>  > |
>  > |   (add-hook 'org-babel-post-tangle-hook
> 'org-babel-mark-file-as-tangled)
>  > `----
>
>  > I assume this is a bug somewhere?
>
>  > Org-mode version 8.0.3 (release_8.0.3-211-gf16b53 @
>  > /home/rkrug/.emacs.d/org-mode/lisp/)
>
>  > GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.6.4)
>  >  of 2013-04-14 on actinium, modified by Debian
>
>  > 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 (F):       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug

[-- Attachment #2: Type: text/html, Size: 5225 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-07 15:40   ` Rainer M Krug
@ 2013-06-07 16:48     ` Vitalie Spinu
  2013-06-10  8:27       ` Rainer M Krug
  2013-06-08  7:47     ` Nick Dokos
  1 sibling, 1 reply; 8+ messages in thread
From: Vitalie Spinu @ 2013-06-07 16:48 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Rainer M Krug, emacs-orgmode@gnu.org

 >> Rainer M Krug <r.m.krug@gmail.com>
 >> on Fri, 7 Jun 2013 17:40:53 +0200 wrote:

 > On Friday, June 7, 2013, Vitalie Spinu wrote:
 >     All your examples are placed in fundamental mode. The comments are
 >     treated by org and thus are correct, local variables are inserted
 >     according to the major mode.

 > The question is why - all .R files are automatically in r mode when I open them
 > and all other R files tangle fine.

Because they are placed automatically in R mode, your files are in
fundamental mode.

    Vitalie

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-07 15:40   ` Rainer M Krug
  2013-06-07 16:48     ` Vitalie Spinu
@ 2013-06-08  7:47     ` Nick Dokos
  1 sibling, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2013-06-08  7:47 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <r.m.krug@gmail.com> writes:

> On Friday, June 7, 2013, Vitalie Spinu wrote:
>
>     All your examples are placed in fundamental mode. The comments are
>     treated by org and thus are correct, local variables are inserted
>     according to the major mode.
>
> The question is why - all .R files are automatically in r mode when I
> open them and all other R files tangle fine. 
>
That's because the auto-mode-alist tells emacs that .R files should be
in R-mode, so after emacs opens the file, it calls the R-mode function.

>     I don't how this could be easily fixed on org side, but you can
>     solve it straightforwardly with:
>    
>     (add-to-list 'auto-mode-alist (cons "NAME\\|DESC" 'R-mode))
>
> Ok - I'check it out on Monday.
>

That's one way: it's got its downside in that the names have to match,
so you have to remember to modify the auto-mode-alist when you use
different names when tangling.

Another way is to modify the function below:

>     > I use the following in my .emacs file to set the
>     > post-tangle-hook to add the local file variables:
>    
>     > ,----
>     > |  (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 ()
              (R-mode)  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>     > |     (add-file-local-variable 'org-babel-tangled-file t)
>     > |     (add-file-local-variable 'buffer-read-only t)
>     > |     ;; (add-file-local-variable 'eval: (auto-revert-mode))
>     > |     (basic-save-buffer))
>     > |
>     > |  (add-hook 'org-babel-post-tangle-hook
>     > |            'org-babel-mark-file-as-tangled)
>     > `----
>    
>    

to call R-mode explicitly. That's got its own downside: all your
tangled files are going to be in R-mode.

The point is that you have to tell emacs somehow what you are doing:
it can't guess that you are producing R-mode files without some help.

-- 
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-07 16:48     ` Vitalie Spinu
@ 2013-06-10  8:27       ` Rainer M Krug
  2013-06-10 13:19         ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Rainer M Krug @ 2013-06-10  8:27 UTC (permalink / raw)
  To: emacs-orgmode

Vitalie Spinu <spinuvit@gmail.com> writes:

>  >> Rainer M Krug <r.m.krug@gmail.com>
>  >> on Fri, 7 Jun 2013 17:40:53 +0200 wrote:
>
>  > On Friday, June 7, 2013, Vitalie Spinu wrote:
>  >     All your examples are placed in fundamental mode. The comments are
>  >     treated by org and thus are correct, local variables are inserted
>  >     according to the major mode.
>
>  > The question is why - all .R files are automatically in r mode when I open them
>  > and all other R files tangle fine.
>
> Because they are placed automatically in R mode, your files are in
> fundamental mode.

I think I get it now: my files are interpreted by emacs as fundamental
files. But when I visit them in a buffer, the buffer is interpreted as
an R buffer.

Thanks.

Rainer


>
>     Vitalie
>
>
>
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-10  8:27       ` Rainer M Krug
@ 2013-06-10 13:19         ` Nick Dokos
  2013-06-10 14:55           ` Rainer M Krug
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2013-06-10 13:19 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <Rainer@krugs.de> writes:

> Vitalie Spinu <spinuvit@gmail.com> writes:
>
>>  >> Rainer M Krug <r.m.krug@gmail.com>
>>  >> on Fri, 7 Jun 2013 17:40:53 +0200 wrote:
>>
>>  > On Friday, June 7, 2013, Vitalie Spinu wrote:
>>  >     All your examples are placed in fundamental mode. The comments are
>>  >     treated by org and thus are correct, local variables are inserted
>>  >     according to the major mode.
>>
>>  > The question is why - all .R files are automatically in r mode when I open them
>>  > and all other R files tangle fine.
>>
>> Because they are placed automatically in R mode, your files are in
>> fundamental mode.
>
> I think I get it now: my files are interpreted by emacs as fundamental
> files. But when I visit them in a buffer, the buffer is interpreted as
> an R buffer.
>

Almost. Files are *opened* in some mode: if no other mode is
found, they are opened in fundamental mode - by themselves, they are not
"fundamental files" or "R-mode files" or ... That's an interpretation
that emacs superimposes on them when it visits them. To do that, it uses
information in auto-mode-alist, or in any mode specification in the file
itself (using file-local variables embedded in comments).

So when you open a file "foo", it will be opened in fundamental mode
(absent some other specification in the auto-mode-alist). When you add
contents, the mode does not change. If you save it as file "foo" and
then reopen it, it will still be in fundamental mode.  But if you save
it as "foo.org" and then reopen it, the auto-mode-alist will tell emacs
to change the mode to org-mode (assuming that the .org suffix has been
set up correctly in the auto-mode-alist).  It does not matter what the
contents were: it could be a C program e.g.  and it would still be
opened in org mode.

-- 
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Wrong comment character when adding file local variables?
  2013-06-10 13:19         ` Nick Dokos
@ 2013-06-10 14:55           ` Rainer M Krug
  0 siblings, 0 replies; 8+ messages in thread
From: Rainer M Krug @ 2013-06-10 14:55 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2630 bytes --]


Nick Dokos <ndokos@gmail.com> writes:

> Rainer M Krug <Rainer@krugs.de> writes:
>
>> Vitalie Spinu <spinuvit@gmail.com> writes:
>>
>>>  >> Rainer M Krug <r.m.krug@gmail.com>
>>>  >> on Fri, 7 Jun 2013 17:40:53 +0200 wrote:
>>>
>>>  > On Friday, June 7, 2013, Vitalie Spinu wrote:
>>>  >     All your examples are placed in fundamental mode. The comments are
>>>  >     treated by org and thus are correct, local variables are inserted
>>>  >     according to the major mode.
>>>
>>>  > The question is why - all .R files are automatically in r mode when I open them
>>>  > and all other R files tangle fine.
>>>
>>> Because they are placed automatically in R mode, your files are in
>>> fundamental mode.
>>
>> I think I get it now: my files are interpreted by emacs as fundamental
>> files. But when I visit them in a buffer, the buffer is interpreted as
>> an R buffer.
>>
>
> Almost. Files are *opened* in some mode: if no other mode is
> found, they are opened in fundamental mode - by themselves, they are not
> "fundamental files" or "R-mode files" or ... That's an interpretation
> that emacs superimposes on them when it visits them. To do that, it uses
> information in auto-mode-alist, or in any mode specification in the file
> itself (using file-local variables embedded in comments).
>
> So when you open a file "foo", it will be opened in fundamental mode
> (absent some other specification in the auto-mode-alist). When you add
> contents, the mode does not change. If you save it as file "foo" and
> then reopen it, it will still be in fundamental mode.  But if you save
> it as "foo.org" and then reopen it, the auto-mode-alist will tell emacs
> to change the mode to org-mode (assuming that the .org suffix has been
> set up correctly in the auto-mode-alist).  It does not matter what the
> contents were: it could be a C program e.g.  and it would still be
> opened in org mode.

Thanks for this very clear description of how this happened. I think I
understand what is going here.

And now I see why the block NAMESPACE file uses the R comment character,
while the others don't: NAMESPACE is in the auto-mode-alist defined as
an R file.
Adding DESCRIPTION as an R file would not be useful, as it is not an R
file - it follows the Debian Control File rules. I dont think there is a
mode for these?

But wouldn't this mechanism be an argument for a header argument to
enable adding of the mode of the file as tangled?
Always adding a local variable to the tangled file might cause problems
with certain formats which do not support comments.

Cheers,

Rainer

-- Rainer M. Krug

email: RMKrug<at>gmail<dot>com

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-06-10 14:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-07 13:12 Wrong comment character when adding file local variables? Rainer M Krug
2013-06-07 13:48 ` Vitalie Spinu
2013-06-07 15:40   ` Rainer M Krug
2013-06-07 16:48     ` Vitalie Spinu
2013-06-10  8:27       ` Rainer M Krug
2013-06-10 13:19         ` Nick Dokos
2013-06-10 14:55           ` Rainer M Krug
2013-06-08  7:47     ` Nick Dokos

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).