emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Tabs in export of code
@ 2015-01-11 16:31 Giuseppe Lipari
  2015-01-11 18:01 ` Eric S Fraga
  2015-01-12  2:05 ` Charles C. Berry
  0 siblings, 2 replies; 5+ messages in thread
From: Giuseppe Lipari @ 2015-01-11 16:31 UTC (permalink / raw)
  To: emacs-orgmode

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

Dear all,

I am preparing a set of slides with examples of java code. I am using the
beamer exporter, configured for using minted with the following options:


#+BEGIN_SRC emacs-lisp :exports none :results silent
  (setq org-latex-minted-options
        '(("frame" "lines")
          ("bgcolor" "mybg")
          ("fontsize" "\\scriptsize")
          ("mathescape" "")
          ("samepage" "")
          ("xrightmargin" "0.1cm")
          ("xleftmargin"  "0.1cm")
          ))
#+END_SRC


Also, I have my emacs init.org containing:


#+begin_src emacs-lisp
  (setq org-src-fontify-natively  t)
  (setq org-src-tab-acts-natively t)
#+end_src

and later

#+BEGIN_SRC emacs-lisp
  (add-hook 'java-mode-hook (lambda ()
                              (setq c-basic-offset 4
                                    tab-width 4
                                    indent-tabs-mode nil)))
#+END_SRC



Ok, now the problem.I want to export a slide with this snippet:


#+BEGIN_SRC java
  class PrimeThread extends Thread {
      long minPrime;
      PrimeThread(long minPrime) {
          this.minPrime = minPrime;
      }

      public void run() {
          // compute primes larger than minPrime
          ...
      }
  }
  ...
  PrimeThread p = new PrimeThread(143);
  p.start();
#+END_SRC

There is not tab in this snipper (I never use tabs in code, only spaces).
Unfortunately, when opening the tex file, I see that a tab has been
introduced whenever 8 consecutive spaces are found, in particular at line 4.

Here is the produced code:

\begin{frame}[fragile,label=sec-3-2]{Thread implementation through
sub-classing}
 \begin{minted}[frame=lines,bgcolor=mybg,fontsize=\scriptsize,mathescape,samepage,xrightmargin=0.1cm,xleftmargin=0.1cm]{java}
class PrimeThread extends Thread {
    long minPrime;
    PrimeThread(long minPrime) {
    this.minPrime = minPrime;
    }

    public void run() {
    // compute primes larger than minPrime
    ...
    }
}
...
PrimeThread p = new PrimeThread(143);
p.start();
\end{minted}
\end{frame}

As you can maybe see (it depends on how your email client shows tabs),
there is a tab character in front of the fourth line.

Where this tab comes from? Is there any org-mode variable I can configure
to prevent this behaviour? I did a quick search on google, but could find
nothing


Thanks in advance

Giuseppe Lipari


-- 
Giuseppe Lipari
LIFL
Université de Lille 1
blogs: http://scacciamennule.blogspot.com  (Italian)
<http://scacciamennule.blogspot.com>
          http://okpanico,wordpress.com          (Italian)
          http://algoland.wordpress.com           (English)

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

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

* Re: Tabs in export of code
  2015-01-11 16:31 Tabs in export of code Giuseppe Lipari
@ 2015-01-11 18:01 ` Eric S Fraga
  2015-01-11 18:30   ` Giuseppe Lipari
  2015-01-12  2:05 ` Charles C. Berry
  1 sibling, 1 reply; 5+ messages in thread
From: Eric S Fraga @ 2015-01-11 18:01 UTC (permalink / raw)
  To: Giuseppe Lipari; +Cc: emacs-orgmode

On Sunday, 11 Jan 2015 at 17:31, Giuseppe Lipari wrote:

[...]

> There is not tab in this snipper (I never use tabs in code, only spaces).
> Unfortunately, when opening the tex file, I see that a tab has been
> introduced whenever 8 consecutive spaces are found, in particular at line 4.

Shot in the dark: are tabs inserted when code is auto-indented?  If so,
maybe:

,----[ C-h v indent-tabs-mode RET ]
| indent-tabs-mode is a variable defined in `C source code'.
| Its value is nil
| Original value was t
| Local in buffer *unsent wide reply to Giuseppe Lipari*; global value is the same.
| 
|   Automatically becomes buffer-local when set.
|   This variable is safe as a file local variable if its value
|   satisfies the predicate `booleanp'.
| 
| Documentation:
| Indentation can insert tabs if this is non-nil.
| 
| You can customize this variable.
| 
`----

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-703-gef523b.dirty

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

* Re: Tabs in export of code
  2015-01-11 18:01 ` Eric S Fraga
@ 2015-01-11 18:30   ` Giuseppe Lipari
  2015-01-11 21:16     ` Grant Rettke
  0 siblings, 1 reply; 5+ messages in thread
From: Giuseppe Lipari @ 2015-01-11 18:30 UTC (permalink / raw)
  To: Giuseppe Lipari, emacs-orgmode

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

Dear Eric,

thanks for your quick answer. However this does not solve the problem.
I use source code fontification for source blocks in org mode:

#+begin_src emacs-lisp
  (setq org-src-fontify-natively  t)
  (setq org-src-tab-acts-natively t)
#+end_src


Normally, when I program in C or java, I disable indent-tabs mode. So, I
have this hook

 (add-hook 'java-mode-hook (lambda ()
                              (setq c-basic-offset 4
                                    tab-width 4
                                    indent-tabs-mode nil)))

somewhere in my init file.

If I understand well what "org-src-fontify-natively" means, it should call
the hook when I edit a code block whose language is Java, and this should
in turn set the variable to nil. In fact, no tab is ever inserted anywhere
in my org file, and the value od "indent-tabs-mode" at the buffer local
level is nil, exactly as in your case. I have no idea if it can be set to
nil at the global level (the documentation seems to say that it is not
possible).

Summarising

    no tab in the org file, --> a tab appears in the tex file

Thanks anyway.

Giuseppe Lipari




2015-01-11 19:01 GMT+01:00 Eric S Fraga <e.fraga@ucl.ac.uk>:

> On Sunday, 11 Jan 2015 at 17:31, Giuseppe Lipari wrote:
>
> [...]
>
> > There is not tab in this snipper (I never use tabs in code, only spaces).
> > Unfortunately, when opening the tex file, I see that a tab has been
> > introduced whenever 8 consecutive spaces are found, in particular at
> line 4.
>
> Shot in the dark: are tabs inserted when code is auto-indented?  If so,
> maybe:
>
> ,----[ C-h v indent-tabs-mode RET ]
> | indent-tabs-mode is a variable defined in `C source code'.
> | Its value is nil
> | Original value was t
> | Local in buffer *unsent wide reply to Giuseppe Lipari*; global value is
> the same.
> |
> |   Automatically becomes buffer-local when set.
> |   This variable is safe as a file local variable if its value
> |   satisfies the predicate `booleanp'.
> |
> | Documentation:
> | Indentation can insert tabs if this is non-nil.
> |
> | You can customize this variable.
> |
> `----
>
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org
> release_8.3beta-703-gef523b.dirty
>



-- 
Giuseppe Lipari
LIFL
Université de Lille 1
blogs: http://scacciamennule.blogspot.com  (Italian)
<http://scacciamennule.blogspot.com>
          http://okpanico,wordpress.com          (Italian)
          http://algoland.wordpress.com           (English)

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

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

* Re: Tabs in export of code
  2015-01-11 18:30   ` Giuseppe Lipari
@ 2015-01-11 21:16     ` Grant Rettke
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Rettke @ 2015-01-11 21:16 UTC (permalink / raw)
  To: Giuseppe Lipari; +Cc: emacs-orgmode@gnu.org

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

Unsure but perhaps these are involved, what are your setting for:

org-src-preserve-indentation

and

org-edit-src-content-indentation

On Sun, Jan 11, 2015 at 12:30 PM, Giuseppe Lipari <giulipari@gmail.com>
wrote:

> Dear Eric,
>
> thanks for your quick answer. However this does not solve the problem.
> I use source code fontification for source blocks in org mode:
>
> #+begin_src emacs-lisp
>   (setq org-src-fontify-natively  t)
>   (setq org-src-tab-acts-natively t)
> #+end_src
>
>
> Normally, when I program in C or java, I disable indent-tabs mode. So, I
> have this hook
>
>  (add-hook 'java-mode-hook (lambda ()
>                               (setq c-basic-offset 4
>                                     tab-width 4
>                                     indent-tabs-mode nil)))
>
> somewhere in my init file.
>
> If I understand well what "org-src-fontify-natively" means, it should call
> the hook when I edit a code block whose language is Java, and this should
> in turn set the variable to nil. In fact, no tab is ever inserted anywhere
> in my org file, and the value od "indent-tabs-mode" at the buffer local
> level is nil, exactly as in your case. I have no idea if it can be set to
> nil at the global level (the documentation seems to say that it is not
> possible).
>
> Summarising
>
>     no tab in the org file, --> a tab appears in the tex file
>
> Thanks anyway.
>
> Giuseppe Lipari
>
>
>
>
> 2015-01-11 19:01 GMT+01:00 Eric S Fraga <e.fraga@ucl.ac.uk>:
>
>> On Sunday, 11 Jan 2015 at 17:31, Giuseppe Lipari wrote:
>>
>> [...]
>>
>> > There is not tab in this snipper (I never use tabs in code, only
>> spaces).
>> > Unfortunately, when opening the tex file, I see that a tab has been
>> > introduced whenever 8 consecutive spaces are found, in particular at
>> line 4.
>>
>> Shot in the dark: are tabs inserted when code is auto-indented?  If so,
>> maybe:
>>
>> ,----[ C-h v indent-tabs-mode RET ]
>> | indent-tabs-mode is a variable defined in `C source code'.
>> | Its value is nil
>> | Original value was t
>> | Local in buffer *unsent wide reply to Giuseppe Lipari*; global value is
>> the same.
>> |
>> |   Automatically becomes buffer-local when set.
>> |   This variable is safe as a file local variable if its value
>> |   satisfies the predicate `booleanp'.
>> |
>> | Documentation:
>> | Indentation can insert tabs if this is non-nil.
>> |
>> | You can customize this variable.
>> |
>> `----
>>
>> --
>> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org
>> release_8.3beta-703-gef523b.dirty
>>
>
>
>
> --
> Giuseppe Lipari
> LIFL
> Université de Lille 1
> blogs: http://scacciamennule.blogspot.com  (Italian)
> <http://scacciamennule.blogspot.com>
>           http://okpanico,wordpress.com          (Italian)
>           http://algoland.wordpress.com           (English)
>



-- 
Grant Rettke
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson

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

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

* Re: Tabs in export of code
  2015-01-11 16:31 Tabs in export of code Giuseppe Lipari
  2015-01-11 18:01 ` Eric S Fraga
@ 2015-01-12  2:05 ` Charles C. Berry
  1 sibling, 0 replies; 5+ messages in thread
From: Charles C. Berry @ 2015-01-12  2:05 UTC (permalink / raw)
  To: Giuseppe Lipari; +Cc: emacs-orgmode

On Sun, 11 Jan 2015, Giuseppe Lipari wrote:

> Dear all,
>
> I am preparing a set of slides with examples of java code. I am using the
> beamer exporter, configured for using minted with the following options:
>

[snip]
>
>
> Ok, now the problem.I want to export a slide with this snippet:
>
>
> #+BEGIN_SRC java
>  class PrimeThread extends Thread {
>      long minPrime;
>      PrimeThread(long minPrime) {
>          this.minPrime = minPrime;
>      }
>
>      public void run() {
>          // compute primes larger than minPrime
>          ...
>      }
>  }
>  ...
>  PrimeThread p = new PrimeThread(143);
>  p.start();
> #+END_SRC
>
> There is not tab in this snipper (I never use tabs in code, only spaces).
> Unfortunately, when opening the tex file, I see that a tab has been
> introduced whenever 8 consecutive spaces are found, in particular at line 4.
>

This happens deep down (in org-indent-line-to, I guess) and AFAICS you do 
not have an option to set to change this.

But you can use a filter function to change the TABs to spaces. This 
seems to handle your case:

#+BEGIN_SRC emacs-lisp
   (add-to-list 'org-export-filter-final-output-functions
                (lambda (x y z)
                  (replace-regexp-in-string "\t" "        " x nil t)))
#+END_SRC

If you want to only do this for src blocks, then use 
`org-export-filter-src-block-functions' instead.


See

 	(info "(org) Advanced configuration")

under `Filters' for details.

HTH,

Chuck

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

end of thread, other threads:[~2015-01-12  2:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-11 16:31 Tabs in export of code Giuseppe Lipari
2015-01-11 18:01 ` Eric S Fraga
2015-01-11 18:30   ` Giuseppe Lipari
2015-01-11 21:16     ` Grant Rettke
2015-01-12  2:05 ` Charles C. Berry

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).