emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: Erik Iverson <eriki@ccbr.umn.edu>
Cc: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>,
	Carsten Dominik <carsten.dominik@gmail.com>
Subject: Native TAB in code blocks [WAS Re: Org now fontifies code blocks]
Date: Thu, 02 Sep 2010 12:06:38 -0700	[thread overview]
Message-ID: <87vd6om0ch.fsf_-_@stats.ox.ac.uk> (raw)
In-Reply-To: <4C7FD932.3070705@ccbr.umn.edu> (Erik Iverson's message of "Thu, 02 Sep 2010 12:04:50 -0500")

Erik Iverson <eriki@ccbr.umn.edu> writes:

> Dan,
>
> Thank you to David and yourself for this great feature.  I have
> absolutely no opinion about the default on/off, except to say it
> looks great on.
>
> Is your TAB key patch[1] in master yet?
> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg28640.html

Hi Erik,

Since these[1] changes, language-native TAB can be achieved in code
blocks via C-c C-v C-x TAB and C-c C-v x TAB. We can add this to
org-tab-first-hook, controlled by a variable `org-src-tab-acts-natively'
as below. Carsten -- would you like to add this to Org, or leave it as a
user customisation?

Dan


--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 6c09cbd..d1948cc 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -715,6 +715,19 @@ Org-babel commands."
      (call-interactively
       (lookup-key org-babel-map key)))))
 
+(defvar org-src-tab-acts-natively nil
+  "If non-nil, the effect of TAB in a code block is as if it were
+issued in the language major mode buffer.")
+
+(defun org-src-native-tab-command-maybe ()
+  "Perform language-specific TAB action.
+Alter code block according to effect of TAB in the language major
+mode."
+  (and org-src-tab-acts-natively
+       (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB"))))
+
+(add-hook 'org-tab-first-hook 'org-src-native-tab-command-maybe)
+
 (defun org-src-font-lock-fontify-block (lang start end)
   "Fontify code block.
 This function is called by emacs automatic fontification, as long
--8<---------------cut here---------------end--------------->8---


Footnotes:

[1] http://thread.gmane.org/gmane.emacs.orgmode/28950

>
>
>
> Dan Davison wrote:
>> I've just pushed changes which mean that Org now fontifies code in code
>> blocks. Currently, this is turned on by default, so it would be helpful
>> if people could report any problems, and opinions as to whether it
>> should be on or off by default.
>>
>> To turn it off, use
>>
>> (setq org-src-fontify-natively nil)
>>
>> With it off, there are two functions for manually fontifying code
>> blocks: `org-src-fontify-block' and `org-src-fontify-buffer'.
>>
>> With it on, on my netbook, there is a slight delay when typing in code
>> blocks of over 100 lines in length, and this is pronounced in code
>> blocks of several hundred lines.
>>
>> Just to be clear, this is fontification only -- no other language major
>> mode features -- so the default method of editing code is still C-c '
>> (org-edit-src-code).
>>
>> Thanks to David O'Toole for the original patch. The final version of the
>> patch is based on Carsten's suggestions for a more efficient
>> implementation.
>>
>> Dan
>>
>>
>> Dan Davison <davison@stats.ox.ac.uk> writes:
>>
>>> Dan Davison <davison@stats.ox.ac.uk> writes:
>>>
>>>> "David O'Toole" <dto1138@gmail.com> writes:
>>>>
>>>>> I've got a preliminary patch that adds optional "native" fontification
>>>>> for source blocks. It uses the block's declared mode to fontify the
>>>>> block text. So now blocks look the way they should, and this opens the
>>>>> way to further enhancements.
>>>> Hi David,
>>>>
>>>> This is great! Here's a patch which allows the src blocks to have
>>>> switches and header args, and also uses `org-src-lang-modes' to find the
>>>> major mode. 
>>> I'm resending this as a match against the current master branch, and as
>>> an attachment so that it goes into the patchwork system. I am keeping
>>> this line of patches in branch `src-block-fontification' at
>>> git://github.com/dandavison/org-devel.git
>>>
>>> Dan
>>>
>>>
>>> _______________________________________________
>>> Emacs-orgmode mailing list
>>> Please use `Reply All' to send replies to the list.
>>> Emacs-orgmode@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>>
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-09-02 19:07 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03 23:12 [PATCH] Mode-specific fontification of babel source blocks David O'Toole
2010-08-03 23:14 ` David O'Toole
2010-08-03 23:23   ` Erik Iverson
2010-08-04  2:55 ` Dan Davison
2010-08-04  5:55   ` David O'Toole
2010-08-09 21:35   ` Dan Davison
2010-09-02 15:51     ` Org now fontifies code blocks Dan Davison
2010-09-02 17:04       ` Erik Iverson
2010-09-02 19:06         ` Dan Davison [this message]
2010-09-02 19:18           ` Native TAB in code blocks [WAS Re: Org now fontifies code blocks] Carsten Dominik
2010-09-02 20:36             ` Native TAB in code blocks Dan Davison
2010-09-03  8:11               ` Julien Fantin
2010-09-02 20:26       ` Org now fontifies " Sébastien Vauban
2010-09-03 17:30       ` Eric S Fraga
2010-09-03 19:10         ` Thomas S. Dye
2010-09-06 16:49           ` David O'Toole
2010-09-07 13:23           ` Dan Davison
2010-09-07 13:55             ` Richard Riley
2010-09-07 16:05             ` Thomas S. Dye
2010-09-08 16:36               ` Darlan Cavalcante Moreira
2010-09-08 17:41                 ` Dan Davison
2010-09-09 13:02                   ` Darlan Cavalcante Moreira
2010-09-09 21:40                     ` Thomas S. Dye
2010-09-09 22:35                       ` Dan Davison
2010-09-09 23:03                         ` Thomas S. Dye
2010-10-28 11:10                           ` Dan Davison
2010-10-28 12:08                             ` Jules Bean
2010-10-28 12:47                               ` Jambunathan K
2010-10-28 13:35                                 ` Dan Davison
2010-10-28 16:24                             ` Thomas S. Dye
2010-09-06 16:59         ` Richard Riley
2010-09-06 17:53           ` David O'Toole
2010-09-06 18:30             ` Bastien
2010-09-06 18:52               ` David O'Toole
2010-09-06 18:59                 ` Richard Riley
2010-09-07 13:43                 ` Dan Davison
2010-09-07 14:22                   ` Carsten Dominik
2010-09-07 14:33                     ` Bastien
2010-09-07 14:37                       ` Carsten Dominik
2010-09-07 14:41                       ` Sebastian Rose
2010-09-07 16:20                         ` Dan Davison
2010-09-07 15:03                       ` Sébastien Vauban
2010-09-07 16:54                     ` Dan Davison
2010-09-08 16:30                       ` Bastien
2010-09-08 18:35                         ` Sébastien Vauban
2010-09-08 18:42                           ` Erik Iverson
2010-09-08 19:17                             ` Dan Davison
2010-09-07 14:24                   ` Bastien
2010-09-07 14:33                   ` Tom Short
2010-09-07 14:47                     ` Richard Riley
2010-09-06 17:59           ` Erik Iverson
2010-09-06 18:23           ` Dan Davison
2010-09-06 18:49             ` Richard Riley
2010-09-07 13:33               ` Dan Davison
2010-09-07  7:24           ` Sébastien Vauban
2010-08-15  6:33 ` [PATCH] Mode-specific fontification of babel source blocks Dan Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vd6om0ch.fsf_-_@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=eriki@ccbr.umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).