From 9ebafe20ec630ace4ec042e7f59e41baadcf8859 Mon Sep 17 00:00:00 2001 From: Rui Miguel Silva Date: Thu, 28 Jun 2012 10:36:20 +0100 Subject: [PATCH 1/5] add: support for MobileOrg push/pull using emacsclient --- _vimrc | 7 ++ doc/vimorg.txt | 39 +++++++++++ ftplugin/org.vim | 104 ++++++++++++++++++++++++++++++ ftplugin/vimorg-main-mappings.vim | 4 ++ 4 files changed, 154 insertions(+) diff --git a/_vimrc b/_vimrc index f5df047..fa4b27a 100644 --- a/_vimrc +++ b/_vimrc @@ -44,6 +44,13 @@ let g:org_tags_alist='{@home(h) @work(w) @tennisclub(t)} {easy(e) hard(d)} {comp let g:org_agenda_select_dirs=["~/desktop/org_files"] let g:org_agenda_files = split(glob("~/desktop/org_files/org-mod*.org"),"\n") +" MobileOrg specific variables needed to Push/Pull to the mobile application +" for synchornization + +let g:org_mobile_directory=["~/desktop/org_files/mobile"] +let g:org_mobile_files=["~/desktop/org_files/projects.org","~/desktop/org_files/personal.org"] +let g:org_mobile_inbox_for_pull=["~/desktop/org_files/mobile/from-mobileorg.org"] + " ---------------------- " Emacs setup " ---------------------- diff --git a/doc/vimorg.txt b/doc/vimorg.txt index c1e0910..2917bf8 100644 --- a/doc/vimorg.txt +++ b/doc/vimorg.txt @@ -284,6 +284,45 @@ issuing the command manually within Emacs (alt-x server-start). ---------------------------------------------------------------------------- +INTERACTING WITH MOBILEORG AND VIMORGANIZER *vimorg-mobileorg-interaction* + *vimorg-mobileorg-setup* + +Vim/VimOrganizer allows users to synchronize with the MobileOrg applications. For +this it uses Emacs client, so Emacs client need to be properly configure to +use this feature. (see |vimorg-emacs-setup|) + +MobileOrg applications for iOS (http://mobileorg.ncogni.to/) or Android +(https://github.com/matburt/mobileorg-android/wiki/) allow users to change, +remove or capture on the mobile devices. But for that the user need to push their +local agendas files and after pull to get the capture notes from the devices. + +For the VimOrganizer functions OrgExportToMobileOrg() and +OrgImportFromMobileOrg() to work you need first to setup some variables in +your vimrc file, e.g.: +> + let g:org_mobile_directory = ["~/documents/org_files/mobile"] + +This will be the directory where the push command will create the index.org, +checksum and other files to be fetch by the MobileOrg application. +> + let g:org_mobile_files = ["~/documents/org_files/projects.org", "~/documents/org_files/personal.org"] + +This are the list of files that you want to synchronize with the MobileOrg, +since you may not want all your .org files to be push. +> + let g:org_mobile_inbox_for_pull = + ["~/documents/org_files/mobile/from-mobile.org"] + +This is the file where the MobileOrg will write the notes capture by you when +on the move. Afterwards you will need to refile the notes where you desire. + +You can issue the push/pull using the Org menu entries for this or using the +following shotcuts: +,me Push/Export to MobileOrg +,mi Pull/Import From MobileOrg + +---------------------------------------------------------------------------- + CONVERSION BETWEEN ORG-MODE AND VIMORGANIZER *vimorg-orgmode-conversion* In practice nothing may go drastically wrong if you don't have perfect diff --git a/ftplugin/org.vim b/ftplugin/org.vim index 017dfb1..1e38fa6 100644 --- a/ftplugin/org.vim +++ b/ftplugin/org.vim @@ -7432,6 +7432,107 @@ function! OrgExportDashboard() endfunction + +function! s:OrgHasMobileOrgVar() + let result = 1 + + if s:OrgHasEmacsVar() == 0 + let result = 0 + return result + endif + + if !exists("g:org_mobile_files") || (g:org_mobile_files == []) || !exists("g:org_mobile_directory") || (g:org_mobile_directory == '') || !exists("g:org_mobile_inbox_for_pull") || (g:org_mobile_inbox_for_pull == '') + let msg = "=============================================== \n" + \ . "You're trying to call out to Emacs MobileOrg Push or Pull \n" + \ . "you haven't set the necessary variables. \n" + \ . "You should set this in your vimrc by including \n" + \ . "a line like: \n\n" + \ . " let g:org_mobile_directory=[directory where MobileOrg file will be pushed] \n\n" + \ . " let g:org_mobile_files=[agenda files that you would like to be pushed] \n\n" + \ . " let g:org_mobile_inbox_for_pull=[file in which will appear your pulls from MobileOrg] \n\n" + \ . "See :h vimorg-mobileorg-setup for more info. \n\n" + \ . "The call you attempted to Emacs will now be aborted. \n" + \ . "Revise your vimrc and restart Vim to use this feature.\n" + \ . "==============================================\n" + \ . "Press to continue." + call input(msg) + let result = 0 + endif + + return result +endfunction + +function! s:OrgSetMobileOrgVar() + let org_mob_files = map(copy(g:org_mobile_files), '"\\" . "\"" . v:val . "\\" . "\""') + let orgpath = g:org_command_for_emacsclient . ' -n --eval ' + let g:mypart1 = '(custom-set-variables ' . "\'" . '(org-mobile-files (list ' . join(org_mob_files) . '))' + let g:mypart1 .= ' ' . "\'" . '(org-mobile-directory \' . '"' . g:org_mobile_directory . '\' . '")' + let g:mypart1 .= ' ' . "\'" . '(org-mobile-inbox-for-pull \' . '"' . (g:org_mobile_inbox_for_pull) . '\' . '"))' + + let orgcmd = orgpath . '"' . g:mypart1 . '"' + let g:orgcmd = orgcmd + echo "Setting mobile org variables... " + silent! execute '!' . orgcmd + echo "Setting mobile org variables... Done " +endfunction + +function! OrgExportToMobileOrg() + + if s:OrgHasMobileOrgVar() == 0 + return + endif + + call s:OrgSetMobileOrgVar() + + let orgpath = g:org_command_for_emacsclient . ' -n --eval ' + "need to close all opened buffers that belong to the mobile org list + let g:mypart1 = '(dolist (x org-mobile-files) (let((org-export-babel-evaluate t)(org-confirm-babel-evaluate nil)(buf (find-file x))) (progn (set-buffer buf)(revert-buffer t t t) (not-modified) (kill-this-buffer))))' + let orgcmd1 = orgpath . '"' . g:mypart1 . '"' + echo "Closing exporting files to mobile org... " + silent! execute '!' . orgcmd1 + redraw + + let g:mypart2 = ' (progn (org-mobile-push))' + + let orgcmd = orgpath . '"' . g:mypart2 . '"' + let g:orgcmd = orgcmd + echo "Exporting to mobile org... " + silent! execute '!' . orgcmd + redraw + echo "Exporting to mobile org... Done " + redraw + + "need to close all opened buffers + let g:mypart3 = '(dolist (x org-mobile-files) (let((org-export-babel-evaluate t)(org-confirm-babel-evaluate nil)(buf (find-file x))) (progn (set-buffer buf) (not-modified) (kill-this-buffer))))' + let orgcmd3 = orgpath . '"' . g:mypart3 . '"' + echo "Closing again exporting files to mobile org..." + silent! execute '!' . orgcmd3 + redraw! + echo "Closing again exporting files to mobile org... Done " +endfunction + +function! OrgImportFromMobileOrg() + if s:OrgHasMobileOrgVar() == 0 + return + endif + + call s:OrgSetMobileOrgVar() + + let orgpath = g:org_command_for_emacsclient . ' -n --eval ' + let g:myfilename = substitute(expand("%:p"),'\','/','g') + let g:myfilename = substitute(g:myfilename, '/ ','\ ','g') + let g:mypart1 = '(let ((org-export-babel-evaluate t)(org-confirm-babel-evaluate nil)' + let g:mypart1 .= '(buf (find-file \' . '"' . g:myfilename . '\' . '")) ) (progn ' + let g:mypart2 = ' (set-buffer buf) (org-mobile-pull) (save-buffer) (kill-this-buffer)) )' + let orgcmd = orgpath . '"' . g:mypart1 . g:mypart2 . '"' + let g:orgcmd = orgcmd + redraw + echo "Import from mobile org... " + silent! execute '!' . orgcmd + redraw + echo "Import from mobile org...Done" +endfunction + function! s:MailLookup() Utl openlink https://mail.google.com/mail/?hl=en&shva=1#search/after:2010-10-24+before:2010-10-26 "https://mail.google.com/mail/?hl=en&shva=1#search/after%3A2010-10-24+before%3A2010-10-26 @@ -8335,6 +8436,9 @@ amenu &Org.-Sep6- : amenu &Org.Open\ Capture\ Buffer :call org#CaptureBuffer() amenu &Org.-Sep7- : amenu &Org.Export/Publish\ w/Emacs :call OrgExportDashboard() +amenu &Org.-Sep75- : +amenu &Org.Push\ (export)\ Mobile\ Org\ w/Emacs :call OrgExportToMobileOrg() +amenu &Org.Pull\ (import)\ Mobile\ Org\ w/Emacs :call OrgImportFromMobileOrg() amenu &Org.-Sep8- : amenu &Org.R&e-read\ Config\ Lines :call OrgProcessConfigLines() diff --git a/ftplugin/vimorg-main-mappings.vim b/ftplugin/vimorg-main-mappings.vim index f1f3fd6..0287422 100644 --- a/ftplugin/vimorg-main-mappings.vim +++ b/ftplugin/vimorg-main-mappings.vim @@ -59,6 +59,10 @@ nnoremap pl :call s:MyPopup() nnoremap et :call OrgTagsEdit() +" MobileOrg push (export) / pull (import) +noremap me :call OrgExportToMobileOrg() +noremap mi :call OrgImportFromMobileOrg() + " clear search matching nnoremap cs :let @/='' From 8ba98a98b31515af4541edb7ca3329bee36e49fc Mon Sep 17 00:00:00 2001 From: Rui Miguel Silva Date: Thu, 10 Jan 2013 13:53:11 +0000 Subject: [PATCH 2/5] add: file location where the capture was taken --- autoload/org.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/org.vim b/autoload/org.vim index 881bddb..f799106 100644 --- a/autoload/org.vim +++ b/autoload/org.vim @@ -179,6 +179,8 @@ function! org#CaptureBuffer() echo 'Capture is not set up. Please read docs at :h vimorg-capture.' return endif + let l:savedbufn = bufname('%') + call org#SaveLocation() if bufnr('_Org_Capture_') > 0 exec 'bwipeout! ' . bufnr('_Org_Capture_') endif @@ -196,6 +198,8 @@ function! org#CaptureBuffer() normal ggVGd normal i* silent exec "normal o:<".org#Timestamp().">" + let pos = g:location[1] + silent exec "normal o[[file:".g:location[0]."#line=".pos[1]."]"."[".l:savedbufn."]]" normal gg set nomodified startinsert! From a3cb6a489f01146296e657cadb57a0c4d47dabd1 Mon Sep 17 00:00:00 2001 From: Rodrigo Kassick Date: Wed, 24 Apr 2013 13:23:28 -0300 Subject: [PATCH 3/5] Fix problem with export-as-latex emacs command --- ftplugin/org.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ftplugin/org.vim b/ftplugin/org.vim index f5c5206..c6d3462 100644 --- a/ftplugin/org.vim +++ b/ftplugin/org.vim @@ -2,7 +2,7 @@ " ------------------------------------------------------------- " Version: 0.30 " Maintainer: Herbert Sitz -" Last Change: 2011 Nov 02 +" Last Change: Qua, 24 Abr 2013 12:52:48 -0300 " " Script: http://www.vim.org/scripts/script.php?script_id=3342 " Github page: http://github.com/hsitz/VimOrganizer @@ -7408,6 +7408,10 @@ function! OrgExportDashboard() let command_part2 = ' org-publish-' . mydict[key] elseif item == 'g' let command_part2 = ' org-babel-tangle' + elseif item == 'l' + let command_part2 = ' org-latex-export-to-latex' + elseif item == 'p' + let command_part2 = ' org-latex-export-to-pdf' else let command_part2 = ' org-export-as-' . mydict[key] endif From 956f3426a10d932b394c2ac4526445df8e98cda8 Mon Sep 17 00:00:00 2001 From: Rodrigo Kassick Date: Thu, 25 Apr 2013 19:40:08 -0300 Subject: [PATCH 4/5] partial --- indent/org.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/indent/org.vim b/indent/org.vim index 1ef6aaa..9cc9ae2 100644 --- a/indent/org.vim +++ b/indent/org.vim @@ -2,7 +2,7 @@ " ------------------------------------------------------------- " Version: 0.30 " Maintainer: Herbert Sitz -" Last Change: 2011 Nov 02 +" Last Change: Qui, 25 Abr 2013 19:38:28 -0300 " " Script: http://www.vim.org/scripts/script.php?script_id=3342 " Github page: http://github.com/hsitz/VimOrganizer @@ -32,6 +32,7 @@ setlocal nolisp setlocal nosmartindent setlocal autoindent "setlocal indentkeys+=},=\\item,=\\bibitem +setlocal indentkeys+==+ " Only define the function once @@ -63,6 +64,10 @@ function! GetOrgIndent(...) let prevline = getline(prevnonblank(v:lnum-1)) endif + let g:org_indent_debug_cur=curline + let g:org_indent_debug_prev=prevline + let g:org_indent_debug_my_rule='no' + if (curline =~ '^\s*$') && (b:v.suppress_list_indent == 1) let b:v.suppress_list_indent = 0 let b:v.org_list_offset=0 @@ -85,6 +90,9 @@ function! GetOrgIndent(...) " \ && (len(synstack(v:lnum-1,1))>0) " \ && (synIDattr(synstack(v:lnum-1,1)[0],'name') == 'orgList') " let b:v.suppress_list_indent = 0 + "elseif curline =~ '^\s\+' + "(curline =~ '^\s\+'\([+\*#] \|[\d\+[.:)-] \)') + " let g:org_indent_debug_my_rule='yes' elseif b:v.suppress_indent == 1 return indent(curline) elseif b:v.suppress_list_indent == 1 @@ -103,9 +111,16 @@ function! GetOrgIndent(...) elseif prevline =~ '^\s*\d\+[).\]:]\s\+\S' let ind = ind + len(matchstr(prevline,'^\s*\zs\d\+[).\]:]\s\+\ze\S')) elseif prevline =~ '^\s*[-+\*]\s\+\S' + let g:org_debug_i_am_here='yes' let ind = ind + len(matchstr(prevline,'^\s*\zs[-+\*]\s\+\ze\S')) + if curline =~ '^\s*[-+\*]\s\+\S' + let lenmatch=len(matchstr(curline,'^\s*[-+\*]\s\+\S') + let ind=ind-lenmatch + let g:org_indent_debug_my_rule='yes' + endif elseif (len(synstack(v:lnum,1))>0) && (synIDattr(synstack(v:lnum,1)[0],'name') == 'orgList') let ind = len(matchstr(getline(v:lnum-1),'^\s*')) + else endif return ind From f7e60a570d08d75bd04701e42fbdda97bf8402bf Mon Sep 17 00:00:00 2001 From: Rodrigo Kassick Date: Thu, 25 Apr 2013 19:40:08 -0300 Subject: [PATCH 5/5] partial --- indent/org.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/indent/org.vim b/indent/org.vim index 1ef6aaa..9cc9ae2 100644 --- a/indent/org.vim +++ b/indent/org.vim @@ -2,7 +2,7 @@ " ------------------------------------------------------------- " Version: 0.30 " Maintainer: Herbert Sitz -" Last Change: 2011 Nov 02 +" Last Change: Qui, 25 Abr 2013 19:38:28 -0300 " " Script: http://www.vim.org/scripts/script.php?script_id=3342 " Github page: http://github.com/hsitz/VimOrganizer @@ -32,6 +32,7 @@ setlocal nolisp setlocal nosmartindent setlocal autoindent "setlocal indentkeys+=},=\\item,=\\bibitem +setlocal indentkeys+==+ " Only define the function once @@ -63,6 +64,10 @@ function! GetOrgIndent(...) let prevline = getline(prevnonblank(v:lnum-1)) endif + let g:org_indent_debug_cur=curline + let g:org_indent_debug_prev=prevline + let g:org_indent_debug_my_rule='no' + if (curline =~ '^\s*$') && (b:v.suppress_list_indent == 1) let b:v.suppress_list_indent = 0 let b:v.org_list_offset=0 @@ -85,6 +90,9 @@ function! GetOrgIndent(...) " \ && (len(synstack(v:lnum-1,1))>0) " \ && (synIDattr(synstack(v:lnum-1,1)[0],'name') == 'orgList') " let b:v.suppress_list_indent = 0 + "elseif curline =~ '^\s\+' + "(curline =~ '^\s\+'\([+\*#] \|[\d\+[.:)-] \)') + " let g:org_indent_debug_my_rule='yes' elseif b:v.suppress_indent == 1 return indent(curline) elseif b:v.suppress_list_indent == 1 @@ -103,9 +111,16 @@ function! GetOrgIndent(...) elseif prevline =~ '^\s*\d\+[).\]:]\s\+\S' let ind = ind + len(matchstr(prevline,'^\s*\zs\d\+[).\]:]\s\+\ze\S')) elseif prevline =~ '^\s*[-+\*]\s\+\S' + let g:org_debug_i_am_here='yes' let ind = ind + len(matchstr(prevline,'^\s*\zs[-+\*]\s\+\ze\S')) + if curline =~ '^\s*[-+\*]\s\+\S' + let lenmatch=len(matchstr(curline,'^\s*[-+\*]\s\+\S') + let ind=ind-lenmatch + let g:org_indent_debug_my_rule='yes' + endif elseif (len(synstack(v:lnum,1))>0) && (synIDattr(synstack(v:lnum,1)[0],'name') == 'orgList') let ind = len(matchstr(getline(v:lnum-1),'^\s*')) + else endif return ind