Permalink
Browse files

better docs, handle empty svg

  • Loading branch information...
1 parent 9d8467c commit 592ce446ac97ad7323ef9711a26ca445d18670ce @jave committed Mar 1, 2011
Showing with 87 additions and 22 deletions.
  1. +15 −4 README.org
  2. +61 −15 inkmacs.el
  3. +9 −1 linkedtext.org
  4. +2 −2 linkedtext2.org
View
@@ -16,8 +16,11 @@ Synchronize Inkscape text nodes with Org mode text nodes.
Edit an Org mode file as usual.
-'m-x inkorg-mode' starts a linked inkscape node. A dbus link is
-established.
+'m-x inkmacs-edit' starts a linked inkscape instance. The svg file
+name is derived from the root node. inkorg-minor-mode is enabled,
+which in turn enables the inkorg mode map detailed below.
+
+Each root node can have its own inkscape document.
'c-m-x' creates or syncs the text of the current org node with an
inkscape node.
@@ -35,11 +38,19 @@ default Inkmacs creates rectangles, but its possible to use any shape.
The Inkscape representation of an Org node is thus two objects. One
flow frame and one text object.
+It can be a little tricky to select the object you want to work with.
+inkorg-mode has (embryonic) support:
+
+'m-x inkorg-select-tree' selects all corresponding inkscape nodes.
+With argument, define a filter:
+'keep-siblings
+'keep-sibling-subtrees
+'keep-subtree
** Image mode support
Create Elisp macros that perform Inkscape edit operations
-'m-x inkscape-open-buffer-file' opens the svg file in the current emacs
+'m-x inkmacs-edit' opens the svg file in the current emacs
buffer in inkscape. A dbus link is established.
** dbus linked inkscape control
@@ -49,7 +60,7 @@ Inkscape.
The inkverb-* methods are interactive and theres a lot of them. So
'm-x inkverb-calligraphic-prefs' in a buffer using inkorg-minor-mode
-for example, will bring up the calligrapdy preference ui.
+for example, will bring up the calligraphy preference ui.
The inkverb-* methods are mosty ui related and take no arguments.
View
@@ -103,15 +103,35 @@ slow the first time, then not so bad."
;;inkscape process management
;;inkscape-desktop
-(defun inkscape-local-instance (&optional force)
- "Create a buffer local instance of inkscape."
+(defvar inkscape-desktop-instances nil)
+
+(defun inkscape-local-instance (file-name &optional force)
+ "Create a context local instance of inkscape."
;;TODO this needs more cleverness
;;handle closing of ink desktop etc
+ ;;TODO inkorg mode should support more than one desktop
+ ;;todo should also do the file name binding
(interactive)
- (if (and (not force) inkscape-desktop-instance)
- (error "There already is a linked inkscape. Try calling with arg to force."))
+ (if (and (not force) (inkscape-desktop))
+ (error "There already is a linked inkscape. "))
(let ((newdesk (car (last (split-string (inkapp-desktop-new inkscape-application ) "/")))))
- (set (make-local-variable 'inkscape-desktop-instance) (inkscape-document-dbus-proxy-create newdesk))))
+ (set (make-local-variable 'inkscape-desktop-instance) (inkscape-document-dbus-proxy-create newdesk))
+ (setq inkscape-desktop-instances (acons file-name inkscape-desktop-instance inkscape-desktop-instances))
+ ;;todo inkdoc-load doesnt like if theres no actual file
+ (unless (file-exists-p file-name)
+ (inkmacs-create-empty-svg file-name))
+ (inkdoc-load inkscape-desktop-instance file-name)))
+
+(defun inkmacs-create-empty-svg (file-name)
+ "Create empty svg file."
+ (with-temp-file file-name
+ (insert
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>
+<svg width=\"100%\" height=\"100%\">
+</svg>
+")
+ (buffer-string)
+ ))
(defun inkscape-local-instance-close ()
"Close the local inkscape instance."
@@ -127,20 +147,39 @@ slow the first time, then not so bad."
"org.inkscape.document"))
(defun inkscape-desktop ()
- "Return the inkscape desktop suitable for the context."
+ "Return the inkscape desktop suitable for the context.
+null if there is no desk. error if there is a broken desk."
;;TODO the inkscape instance is user visible and can go away unexpectedly if the user closes it
;;so we should do some sanity checking here
- (if (inkscape-desktop-alive inkscape-desktop-instance)
- inkscape-desktop-instance
- (error "It seems the desktop is gone. Maybe you closed it. Try m-x inkscape-local-instance to relink.")))
+ ;;TODO inkorg mode should support more than one desktop
+ (let ((desk (if inkorg-mode
+ (cdr (assoc (inkorg-svg-file-name) inkscape-desktop-instances))
+ inkscape-desktop-instance)))
+ (if desk
+ (if (inkscape-desktop-alive desk)
+ desk
+ (error "It seems the desktop is gone. Maybe you closed it."))
+ nil)))
+
+(defun inkmacs-edit ()
+ "Inkscape edit the buffer or org tree."
+ (interactive)
+ (cond
+ ((equal 'image-mode major-mode) ;;TODO check svg
+ (inkscape-open-buffer-file))
+ ((equal 'org-mode major-mode)
+ (progn
+ (inkorg-mode t)
+ (inkscape-local-instance (inkorg-svg-file-name))))
+ (t (error "Don't know how to inkmacs here."))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;,,
;;image mode adapter code
(defun inkscape-open-buffer-file ()
"Open buffer file un a local inkscape instance."
(interactive)
;;TODO check that the buffer contains a SVG file
- (inkscape-local-instance)
- (inkdoc-load (inkscape-desktop) (buffer-file-name)))
+ (inkscape-local-instance (buffer-file-name)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -270,11 +309,18 @@ node, or update the node if it already exists."
(inkdoc-set-text (inkscape-desktop) id (inkorg-entry-text))
(inkorg-create-text-node))))
-(define-minor-mode inkorg-mode "inkorg" nil " inkorg"
- '(( "\e\C-x" . inkorg-create-or-update-text))
- (if inkorg-mode (inkscape-local-instance)
- (inkscape-local-instance-close))
+(defun inkorg-svg-file-name ()
+ "Figure out which svg file to use in this context."
+ (save-excursion
+ (move-beginning-of-line nil)
+ (unless (= 1 (org-outline-level))
+ (org-up-heading-all 100))
+ (let ((file-name (concat (org-get-heading) ".svg")))
+ (set-text-properties 0 (length file-name) nil file-name)
+ (concat (mapconcat (lambda (e) e) (butlast (split-string (buffer-file-name ) "/")) "/") "/" file-name))))
+(define-minor-mode inkorg-mode "inkorg" nil " inkorg"
+ '(( "\e\C-x" . inkorg-create-or-update-text))
)
(defun inkmacs-node-exists (desk name)
View
@@ -1,4 +1,4 @@
-* file
+* linkedtext
:PROPERTIES:
:ID: 6820fc9a-86b6-487d-bdad-bcbf8fbb8da3
:END:
@@ -34,3 +34,11 @@ I N K M A C S ?
:PROPERTIES:
:ID: 88a09eaf-e36c-48fb-b8d7-25c610628033
:END:
+* otherfile
+ :PROPERTIES:
+ :ID: 97ff5adb-4657-42c4-a00e-3aab2ea302aa
+ :END:
+** other linked org file
+ :PROPERTIES:
+ :ID: 52545c16-8301-416b-9484-7144f7bf0ab4
+ :END:
View
@@ -2,11 +2,11 @@
:PROPERTIES:
:ID: 6820fc9a-86b6-487d-bdad-bcbf8fbb8da3
:END:
-** Multi buffer support!
+** Multi buffer aeouaeosupport!
:PROPERTIES:
:ID: 9daeab04-4a68-4b72-a2f9-8bb18122ddf5
:END:
-** newnode
+** newnode eouei
:PROPERTIES:
:ID: 980f1acf-05f3-49be-92b6-e80d5ca423e0
:END:

0 comments on commit 592ce44

Please sign in to comment.