X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/4628bef1eea0f60e846fe6b6591725aa92952de9..322b7dab59b98b5d8625d2cd29e48f1ce605f769:/lisp/org/org-freemind.el
diff --git a/lisp/org/org-freemind.el b/lisp/org/org-freemind.el
index 06285e4b7d..dccdf44929 100644
--- a/lisp/org/org-freemind.el
+++ b/lisp/org/org-freemind.el
@@ -1,11 +1,11 @@
;;; org-freemind.el --- Export Org files to freemind
-;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
-;; Version: 6.35i
+;; Version: 7.4
;;
;; This file is part of GNU Emacs.
;;
@@ -81,31 +81,35 @@
(require 'xml)
(require 'org)
-(require 'rx)
+;(require 'rx)
(require 'org-exp)
(eval-when-compile (require 'cl))
+(defgroup org-freemind nil
+ "Customization group for org-freemind export/import."
+ :group 'org)
+
;; Fix-me: I am not sure these are useful:
;;
;; (defcustom org-freemind-main-fgcolor "black"
;; "Color of main node's text."
;; :type 'color
-;; :group 'freemind)
+;; :group 'org-freemind)
;; (defcustom org-freemind-main-color "black"
;; "Background color of main node."
;; :type 'color
-;; :group 'freemind)
+;; :group 'org-freemind)
;; (defcustom org-freemind-child-fgcolor "black"
;; "Color of child nodes' text."
;; :type 'color
-;; :group 'freemind)
+;; :group 'org-freemind)
;; (defcustom org-freemind-child-color "black"
;; "Background color of child nodes."
;; :type 'color
-;; :group 'freemind)
+;; :group 'org-freemind)
(defvar org-freemind-node-style nil "Internal use.")
@@ -152,11 +156,25 @@ NOT READY YET."
(string :tag "Font name" :value "SansSerif"))
(list :format "%v" (const :format "" font-size)
(integer :tag "Font size" :value 12)))))))
- :group 'freemind)
+ :group 'org-freemind)
;;;###autoload
-(defun org-export-as-freemind (arg &optional hidden ext-plist
+(defun org-export-as-freemind (&optional hidden ext-plist
to-buffer body-only pub-dir)
+ "Export the current buffer as a Freemind file.
+If there is an active region, export only the region. HIDDEN is
+obsolete and does nothing. EXT-PLIST is a property list with
+external parameters overriding org-mode's default settings, but
+still inferior to file-local settings. When TO-BUFFER is
+non-nil, create a buffer with that name and export to that
+buffer. If TO-BUFFER is the symbol `string', don't leave any
+buffer behind but just return the resulting HTML as a string.
+When BODY-ONLY is set, don't produce the file header and footer,
+simply return the content of the document (all top level
+sections). When PUB-DIR is set, use this as the publishing
+directory.
+
+See `org-freemind-from-org-mode' for more information."
(interactive "P")
(let* ((opt-plist (org-combine-plists (org-default-export-plist)
ext-plist
@@ -203,7 +221,20 @@ NOT READY YET."
(let ((name (read-file-name "FreeMind file: "
nil nil nil
(if (buffer-file-name)
- (file-name-nondirectory (buffer-file-name))
+ (let* ((name-ext (file-name-nondirectory (buffer-file-name)))
+ (name (file-name-sans-extension name-ext))
+ (ext (file-name-extension name-ext)))
+ (cond
+ ((string= "mm" ext)
+ name-ext)
+ ((string= "org" ext)
+ (let ((name-mm (concat name ".mm")))
+ (if (file-exists-p name-mm)
+ name-mm
+ (message "Not exported to Freemind format yet")
+ "")))
+ (t
+ "")))
"")
;; Fix-me: Is this an Emacs bug?
;; This predicate function is never
@@ -227,7 +258,7 @@ The characters \"&<> will be escaped."
(dolist (cc chars)
(setq fm-str
(concat fm-str
- (if (< cc 256)
+ (if (< cc 160)
(cond
((= cc ?\") """)
((= cc ?\&) "&")
@@ -265,52 +296,84 @@ will also unescape nn;."
)))
org-str))))
-;; (org-freemind-test-escape)
-(defun org-freemind-test-escape ()
- (let* ((str1 "a quote: \", an amp: &, lt: <; over 256: öåäÖÅÄ")
- (str2 (org-freemind-escape-str-from-org str1))
- (str3 (org-freemind-unescape-str-to-org str2))
+;; (let* ((str1 "a quote: \", an amp: &, lt: <; over 256: öåäÖÅÄ")
+;; (str2 (org-freemind-escape-str-from-org str1))
+;; (str3 (org-freemind-unescape-str-to-org str2)))
+;; (unless (string= str1 str3)
+;; (error "Error str3=%s" str3)))
+
+(defun org-freemind-convert-links-helper (matched)
+ "Helper for `org-freemind-convert-links-from-org'.
+MATCHED is the link just matched."
+ (let* ((link (match-string 1 matched))
+ (text (match-string 2 matched))
+ (ext (file-name-extension link))
+ (col-pos (string-match-p ":" link))
+ (is-img (and (image-type-from-file-name link)
+ (let ((url-type (substring link 0 col-pos)))
+ (member url-type '("file" "http" "https")))))
)
- (unless (string= str1 str3)
- (error "str3=%s" str3))
- ))
+ (if is-img
+ ;; Fix-me: I can't find a way to get the border to "shrink
+ ;; wrap" around the image using
.
+ ;;
+ ;; (concat "
"
+ ;; "
![\""](\"")
"
+ ;; "
"
+ ;; "
" text ""
+ ;; "
")
+ (concat "
"
+ " "
+ " "
+ "" text ""
+ " |
")
+ (concat "
" text ""))))
(defun org-freemind-convert-links-from-org (org-str)
"Convert org links in ORG-STR to freemind links and return the result."
(let ((fm-str (replace-regexp-in-string
- (rx (not (any "[\""))
- (submatch
- "http"
- (opt ?\s)
- "://"
- (1+
- (any "-%.?@a-zA-Z0-9()_/:~="))))
+ ;;(rx (not (any "[\""))
+ ;; (submatch
+ ;; "http"
+ ;; (opt ?\s)
+ ;; "://"
+ ;; (1+
+ ;; (any "-%.?@a-zA-Z0-9()_/:~="))))
+ "[^\"[]\\(http ?://[--:#%&()=?-Z_a-z~]+\\)"
"[[\\1][\\1]]"
- org-str)))
- (replace-regexp-in-string (rx "[["
- (submatch (*? nonl))
- "]["
- (submatch (*? nonl))
- "]]")
- "
\\2"
- fm-str)))
+ org-str
+ nil ;; fixedcase
+ nil ;; literal
+ 1 ;; subexp
+ )))
+ (replace-regexp-in-string
+ ;;(rx "[["
+ ;; (submatch (*? nonl))
+ ;; "]["
+ ;; (submatch (*? nonl))
+ ;; "]]")
+ "\\[\\[\\(.*?\\)]\\[\\(.*?\\)]]"
+ ;;"
\\2"
+ 'org-freemind-convert-links-helper
+ fm-str)))
;;(org-freemind-convert-links-to-org "
link-text")
(defun org-freemind-convert-links-to-org (fm-str)
"Convert freemind links in FM-STR to org links and return the result."
(let ((org-str (replace-regexp-in-string
- (rx "
")))
- space)
- "href=\""
- (submatch (0+ (not (any "\""))))
- "\""
- (0+ (not (any ">")))
- ">"
- (submatch (0+ (not (any "<"))))
- "")
+ ;;(rx "
")))
+ ;; space)
+ ;; "href=\""
+ ;; (submatch (0+ (not (any "\""))))
+ ;; "\""
+ ;; (0+ (not (any ">")))
+ ;; ">"
+ ;; (submatch (0+ (not (any "<"))))
+ ;; "")
+ "
]*[[:space:]]\\)*href=\"\\([^\"]*\\)\"[^>]*>\\([^<]*\\)"
"[[\\1][\\2]]"
fm-str)))
org-str))
@@ -319,29 +382,60 @@ will also unescape nn;."
;;(defun org-freemind-convert-drawers-from-org (text)
;; )
-;; (org-freemind-test-links)
-;; (defun org-freemind-test-links ()
;; (let* ((str1 "[[http://www.somewhere/][link-text]")
;; (str2 (org-freemind-convert-links-from-org str1))
-;; (str3 (org-freemind-convert-links-to-org str2))
-;; )
+;; (str3 (org-freemind-convert-links-to-org str2)))
;; (unless (string= str1 str3)
-;; (error "str3=%s" str3))
-;; ))
+;; (error "Error str3=%s" str3)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Org => FreeMind
+(defvar org-freemind-bol-helper-base-indent nil)
+
+(defun org-freemind-bol-helper (matched)
+ "Helper for `org-freemind-convert-text-p'.
+MATCHED is the link just matched."
+ (let ((res "")
+ (bi org-freemind-bol-helper-base-indent))
+ (dolist (cc (append matched nil))
+ (if (= 32 cc)
+ ;;(setq res (concat res " "))
+ ;; We need to use the numerical version. Otherwise Freemind
+ ;; ver 0.9.0 RC9 can not export to html/javascript.
+ (progn
+ (if (< 0 bi)
+ (setq bi (1- bi))
+ (setq res (concat res " "))))
+ (setq res (concat res (char-to-string cc)))))
+ res))
+;; (setq x (replace-regexp-in-string "\n +" 'org-freemind-bol-nbsp-helper "\n "))
+
(defun org-freemind-convert-text-p (text)
"Convert TEXT to html with
paragraphs."
+ ;; (string-match-p "[^ ]" " a")
+ (setq org-freemind-bol-helper-base-indent (string-match-p "[^ ]" text))
(setq text (org-freemind-escape-str-from-org text))
- (setq text (replace-regexp-in-string (rx "\n" (0+ blank) "\n") "
\n" text))
- ;;(setq text (replace-regexp-in-string (rx bol (1+ blank) eol) "" text))
- ;;(setq text (replace-regexp-in-string (rx bol (1+ blank)) "
" text))
+
+ (setq text (replace-regexp-in-string "\\([[:space:]]\\)\\(/\\)\\([^/]+\\)\\(/\\)\\([[:space:]]\\)" "\\1\\3\\5" text))
+ (setq text (replace-regexp-in-string "\\([[:space:]]\\)\\(\*\\)\\([^*]+\\)\\(\*\\)\\([[:space:]]\\)" "\\1\\3\\5" text))
+
+ (setq text (concat "
" text))
+ (setq text (replace-regexp-in-string "\n[[:blank:]]*\n" "
" text))
+ (setq text (replace-regexp-in-string "\\(?:
\\|\n\\) +" 'org-freemind-bol-helper text))
(setq text (replace-regexp-in-string "\n" "
" text))
- (concat "
"
- (org-freemind-convert-links-from-org text)
- "
\n"))
+ (setq text (concat text ""))
+
+ (org-freemind-convert-links-from-org text))
+
+(defcustom org-freemind-node-css-style
+ "p { margin-top: 3px; margin-bottom: 3px; }"
+ "CSS style for Freemind nodes."
+ ;; Fix-me: I do not understand this. It worked to export from Freemind
+ ;; with this setting now, but not before??? Was this perhaps a java
+ ;; bug or is it a windows xp bug (some resource gets exhausted if you
+ ;; use sticky keys which I do).
+ :group 'org-freemind)
(defun org-freemind-org-text-to-freemind-subnode/note (node-name start end drawers-regexp)
"Convert text part of org node to freemind subnode or note.
@@ -390,11 +484,14 @@ DRAWERS-REGEXP are converted to freemind notes."
"
\n"
"\n"
"\n"
+ (if (= 0 (length org-freemind-node-css-style))
+ ""
+ (concat
"\n"
+ "\n"))
"\n"
"\n"))
(let ((begin-html-mark (regexp-quote "#+BEGIN_HTML"))
@@ -427,21 +524,28 @@ DRAWERS-REGEXP are converted to freemind notes."
"\n"
"\n"
;; Put a note that this is for the parent node
- ""
- ""
- ""
- ""
- ""
- "-- This is more about \"" node-name "\" --"
- "
"
- ""
- ""
- "\n"
+ ;; ""
+ ;; ""
+ ;; ""
+ ;; ""
+ ;; ""
+ ;; "-- This is more about \"" node-name "\" --"
+ ;; "
"
+ ;; ""
+ ;; ""
+ ;; "\n"
+ note-res
"\n" ;; ok
)))
(list node-res note-res))))
-(defun org-freemind-write-node (mm-buffer drawers-regexp num-left-nodes base-level current-level next-level this-m2 this-node-end this-children-visible next-node-start next-has-some-visible-child)
+(defun org-freemind-write-node (mm-buffer drawers-regexp
+ num-left-nodes base-level
+ current-level next-level this-m2
+ this-node-end
+ this-children-visible
+ next-node-start
+ next-has-some-visible-child)
(let* (this-icons
this-bg-color
this-m2-escaped
@@ -503,7 +607,7 @@ DRAWERS-REGEXP are converted to freemind notes."
(insert "
\n")))
)
(with-current-buffer mm-buffer
- (when this-rich-note (insert this-rich-note))
+ ;;(when this-rich-note (insert this-rich-note))
(when this-rich-node (insert this-rich-node))))
num-left-nodes)
@@ -521,11 +625,13 @@ Otherwise give an error say the file exists."
(error "File %s already exists" file))
t))
-(defvar org-freemind-node-pattern (rx bol
- (submatch (1+ "*"))
- (1+ space)
- (submatch (*? nonl))
- eol))
+(defvar org-freemind-node-pattern
+ ;;(rx bol
+ ;; (submatch (1+ "*"))
+ ;; (1+ space)
+ ;; (submatch (*? nonl))
+ ;; eol)
+ "^\\(\\*+\\)[[:space:]]+\\(.*?\\)$")
(defun org-freemind-look-for-visible-child (node-level)
(save-excursion
@@ -573,27 +679,31 @@ Otherwise give an error say the file exists."
node-at-line-last)
(with-current-buffer mm-buffer
(erase-buffer)
- (insert "\n")
+ (setq buffer-file-coding-system 'utf-8)
+ ;; Fix-me: Currentl Freemind (ver 0.9.0 RC9) does not support this:
+ ;;(insert "\n")
(insert "