diff --git a/ORGWEBPAGE/Changes.org b/ORGWEBPAGE/Changes.org
index 76fdec629..ceb7ac1b1 100644
--- a/ORGWEBPAGE/Changes.org
+++ b/ORGWEBPAGE/Changes.org
@@ -32,6 +32,25 @@
** Details
+*** Editing fixed-width regions with picture or artist mode
+
+ The command @C-c '@
(that is =C-c= followed by a
+ single quote) can now also be used to switch to a special
+ editing mode for fixed-width sections. The default mode is
+ =artist-mode= which allows you to create ASCII drawings.
+
+ It works like this: Enter the editing mode with
+ @C-c '@
. An indirect buffer will be created and
+ narrowed to the fixed-width region. Edit the drawing, and
+ press @C-c '@
again to exit.
+
+ Lines in a fixed-width region should be preceded by a colon
+ followed by at least one space. These will be removed during
+ editing, and then added back when you exit the editing mode.
+
+ Using the command in an empty line will create a new
+ fixed-width region.
+
*** New interpretation of prefix arguments when exiting remember
The prefix argument to the `C-c C-c' command that finishes a
remember process is not interpetred differently:
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 5bb653fa5..99fb6c5fe 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -2,6 +2,8 @@
* org.texi (Creating timestamps): Fix documentation of the "C-c ."
command.
+ (Literal examples): Document using artist-mode for ASCII
+ drawings.
2008-06-13 Carsten Dominik
diff --git a/doc/org.texi b/doc/org.texi
index 50e640638..254e025e0 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6925,7 +6925,12 @@ example:
@item C-c '
Edit the source code example at point in its native mode. This works by
switching to an indirect buffer, narrowing the buffer and switching to the
-other mode. You need to exit by pressing @kbd{C-c '} again.
+other mode. You need to exit by pressing @kbd{C-c '} again. Fixed-width
+regions (where each line starts with a colon followed by a space) will be
+edited using @code{artist-mode}@footnote{You may select a different-mode with
+the variable @code{org-edit-fixed-width-region-mode}.} to allow creating
+ASCII drawings easily. Using this command in an empty line will create a new
+fixed-width region.
@end table
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 28413aed5..ec56c9502 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,12 @@
2008-09-05 Carsten Dominik
+ * org.el (org-edit-fixed-width-region): New function.
+ (org-edit-fixed-width-region): Also try
+ `org-edit-fixed-width-region'.
+ (org-edit-fixed-width-region-mode): New option.
+ (org-activate-code): Only interprete lines starting with colon
+ plus a space as example lines.
+
* org-remember.el (org-remember-templates): Add nil instead of
empty strings to fix the length of remember templates.
diff --git a/lisp/org.el b/lisp/org.el
index 7ed2d1f32..af498b0cb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -669,6 +669,16 @@ See also the QUOTE keyword."
:group 'org-edit-structure
:type 'boolean)
+(defcustom org-edit-fixed-width-region-mode 'artist-mode
+ "The mode that should be used to edit fixed-width regions.
+These are the regions where each line starts with a colon."
+ :group 'org-edit-structure
+ :type '(choice
+ (const artist-mode)
+ (const picture-mode)
+ (const fundamental-mode)
+ (function :tag "Other (specify)")))
+
(defcustom org-goto-auto-isearch t
"Non-nil means, typing characters in org-goto starts incremental search."
:group 'org-edit-structure
@@ -3502,8 +3512,8 @@ will be prompted for."
(throw 'exit t))))))
(defun org-activate-code (limit)
- (if (re-search-forward "^[ \t]*\\(:.*\\)" limit t)
- (unless (get-text-property (match-beginning 1) 'face)
+ (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
+ (progn
(remove-text-properties (match-beginning 0) (match-end 0)
'(display t invisible t intangible t))
t)))
@@ -5433,6 +5443,60 @@ exit by killing the buffer with \\[org-edit-src-exit]."
(message "%s" msg)
t)))
+(defun org-edit-fixed-width-region ()
+ "Edit the fixed-width ascii drawing at point.
+This must be a region where each line starts with ca colon followed by
+a space character.
+An indirect buffer is created, and that buffer is then narrowed to the
+example at point and switched to artist-mode. When done,
+exit by killing the buffer with \\[org-edit-src-exit]."
+ (interactive)
+ (let ((line (org-current-line))
+ (case-fold-search t)
+ (msg (substitute-command-keys
+ "Edit, then exit with C-c ' (C-c and single quote)"))
+ (org-mode-p (eq major-mode 'org-mode))
+ beg end lang lang-f)
+ (beginning-of-line 1)
+ (if (looking-at "[ \t]*[^:\n \t]")
+ nil
+ (if (looking-at "[ \t]*\\(\n\\|\\'\\)]")
+ (setq beg (point) end (match-end 0))
+ (save-excursion
+ (if (re-search-backward "^[ \t]*[^:]" nil 'move)
+ (setq beg (point-at-bol 2))
+ (setq beg (point))))
+ (save-excursion
+ (if (re-search-forward "^[ \t]*[^:]" nil 'move)
+ (setq end (match-beginning 0))
+ (setq end (point))))
+ (goto-line line)
+ (if (get-buffer "*Org Edit Picture*")
+ (kill-buffer "*Org Edit Picture*"))
+ (switch-to-buffer (make-indirect-buffer (current-buffer)
+ "*Org Edit Picture*"))
+ (narrow-to-region beg end)
+ (remove-text-properties beg end '(display nil invisible nil
+ intangible nil))
+ (when (fboundp 'font-lock-unfontify-region)
+ (font-lock-unfontify-region (point-min) (point-max)))
+ (cond
+ ((eq org-edit-fixed-width-region-mode 'artist-mode)
+ (fundamental-mode)
+ (artist-mode 1))
+ (t (funcall org-edit-fixed-width-region-mode)))
+ (set (make-local-variable 'org-edit-src-force-single-line) nil)
+ (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
+ (set (make-local-variable 'org-edit-src-picture) t)
+ (goto-char (point-min))
+ (while (re-search-forward "^[ \t]*: " nil t)
+ (replace-match ""))
+ (goto-line line)
+ (org-exit-edit-mode)
+ (org-set-local 'header-line-format msg)
+ (message "%s" msg)
+ t))))
+
(defun org-edit-src-find-region-and-lang ()
"Find the region and language for a local edit.
Return a list with beginning and end of the region, a string representing
@@ -5518,6 +5582,13 @@ the language, a switch telling of the content should be in a single line."
(when font-lock-mode
(font-lock-unfontify-region (point-min) (point-max)))
(put-text-property (point-min) (point-max) 'font-lock-fontified t))
+ (when (org-bound-and-true-p org-edit-src-picture)
+ (goto-char (point-min))
+ (while (re-search-forward "^" nil t)
+ (replace-match ": "))
+ (when font-lock-mode
+ (font-lock-unfontify-region (point-min) (point-max)))
+ (put-text-property (point-min) (point-max) 'font-lock-fontified t))
(kill-buffer (current-buffer))
(and (org-mode-p) (org-restart-font-lock)))
@@ -12971,6 +13042,7 @@ When in an #+include line, visit the include file. Otherwise call
(looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*.*?file=\"\\)\\([^\"\n>]+\\)"))
(find-file (org-trim (match-string 1))))
((org-edit-src-code))
+ ((org-edit-fixed-width-region))
(t (call-interactively 'ffap))))
(defun org-ctrl-c-ctrl-c (&optional arg)