emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Mode-specific fontification of babel source blocks
@ 2010-08-03 23:12 David O'Toole
  2010-08-03 23:14 ` David O'Toole
                   ` (2 more replies)
  0 siblings, 3 replies; 56+ messages in thread
From: David O'Toole @ 2010-08-03 23:12 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

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. Anyone up for an icons theme standard
discussion?

[-- Attachment #2: source-block-fontification.diff --]
[-- Type: text/x-patch, Size: 2983 bytes --]

diff --git a/lisp/org.el b/lisp/org.el
index d2c1fdf..843e4fe 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5005,17 +5005,25 @@ will be prompted for."
 				'(display t invisible t intangible t))
 	t)))
 
+(defvar org-src-fontify-natively nil
+  "When non-nil, fontify source blocks like their major mode would.")
+
 (defun org-fontify-meta-lines-and-blocks (limit)
   "Fontify #+ lines and blocks, in the correct ways."
   (let ((case-fold-search t))
     (if (re-search-forward
-	 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
+	 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\) ?\\(\\(\\w\\|-\\)*\\)"
 	 limit t)
-	(let ((beg (match-beginning 0))
-	      (beg1 (line-beginning-position 2))
-	      (dc1 (downcase (match-string 2)))
-	      (dc3 (downcase (match-string 3)))
-	      end end1 quoting block-type)
+	(let* ((beg (match-beginning 0))
+	       (block-start (match-end 0))
+	       (block-end nil)
+	       (language (downcase (if (stringp (match-string 6))
+				       (match-string 6)
+				       "AAAAAAAAAA")))
+	       (beg1 (line-beginning-position 2))
+	       (dc1 (downcase (match-string 2)))
+	       (dc3 (downcase (match-string 3)))
+	       end end1 quoting block-type)
 	  (cond
 	   ((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
 	    ;; a single line of backend-specific content
@@ -5035,6 +5043,7 @@ will be prompted for."
 		   (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
 		   nil t)  ;; on purpose, we look further than LIMIT
 	      (setq end (match-end 0) end1 (1- (match-beginning 0)))
+	      (setq block-end (match-beginning 0))
 	      (when quoting
 		(remove-text-properties beg end
 					'(display t invisible t intangible t)))
@@ -5044,7 +5053,28 @@ will be prompted for."
 	      (add-text-properties beg beg1 '(face org-meta-line))
 	      (add-text-properties end1 end '(face org-meta-line))
 	      (cond
-	       (quoting
+		(org-src-fontify-natively
+		 (when (and (stringp language) (> (length language) 1))
+		   (let* ((mode-command (intern (concat (substring language 1) "-mode")))
+			  (string (buffer-substring-no-properties block-start block-end))
+			  (modified (buffer-modified-p))
+			  (fontified-output
+			   (with-temp-buffer
+			     (insert string)
+			     (message language)
+			     (funcall mode-command)
+			     (font-lock-fontify-buffer)
+			     (add-text-properties
+			      (point-min) (point-max)
+			      '(font-lock-fontified t fontified t font-lock-multiline t))
+			     (buffer-substring (point-min) (point-max)))))
+		     (when fontified-output
+		       (assert (stringp fontified-output))
+		       (goto-char block-start)
+		       (delete-region block-start block-end)
+		       (insert fontified-output)
+		       (set-buffer-modified-p modified)))))
+		(quoting
 		(add-text-properties beg1 end1 '(face org-block)))
 	       ((not org-fontify-quote-and-verse-blocks))
 	       ((string= block-type "quote")

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

end of thread, other threads:[~2010-10-28 16:25 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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         ` Native TAB in code blocks [WAS Re: Org now fontifies code blocks] Dan Davison
2010-09-02 19:18           ` 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

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