[O] exporting Racket images

2017-10-23 Thread Lawrence Bottorff
I'm using a nice package from a Racket user called MetaPict
, however, I don't know how to export
the image produced. Here's some Racket code calling MetaPict:

#+begin_src scheme :session mainsession :exports both
(require racket/draw metapict metapict/graph)

(set-curve-pict-size 300 300)  ; width and height of image
(ahlength  1.0); size of arrow head

(define (f x) (sin x))

(define p
  (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax
(draw (draw-arrow (curve (pt -10   0) -- (pt 10  0)))  ; x-axis
  (draw-arrow (curve (pt   0 -10) -- (pt  0 10)))  ; y-axis
  (label-rt  "x" (pt 10.2 0))  ; label for x
axis
  (label-top "y" (pt 0 10.2))  ; label for y
axis
  (color "blue" (draw (circle (pt 2 1) 3))); center (2,1)
radius 3
  (color "red"  (draw (graph f -10 10 #:samples 50))

(define (save-pict-as-svg p width height filename [exists 'replace])
  (define dc (new svg-dc%
  [width width]
  [height height]
  [output filename]
  [exists exists]))
  (send dc start-doc "An SVG Test")  ; a message
  (send dc start-page)
  (draw-pict p dc 0 0)
  (send dc end-page)
  (send dc end-doc))

(save-pict-as-svg p 300 300 "images/outtestmetapict1.svg")
#+end_src

No surprise, but orgmode doesn't know that the image output

(save-pict-as-svg p 300 300 "images/outtestmetapict1.svg")

should be the code block's results. And adding #+RESULTS: over a hand-added
[[file:images/outtestmetapict1.svg]] link makes it not display. I'm
guessing this means orgmode does things internally with, say, gnuplot to
make the generated image the results *and *obey the :exports both . . . Any
ideas how I can get this gnuplot-like behavior with Racket MetaPict? I'm
guessing a customization of the underlying babel code is necessary. . . .

LB


Re: [O] function for inserting a block

2017-10-23 Thread Eric Abrahamsen
Eric Abrahamsen  writes:

> Nicolas Goaziou  writes:
>
>> Hello,
>>
>> Eric Abrahamsen  writes:
>>
>>> Kaushal Modi  writes:
>>>
 On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:
>>>
>>> [...]
>>>
 @Eric: I believe you were sort of onboard with this suggestion, just gated 
 by a doubt if this actually can make into master. 
>>>
>>> In principle yes, I agree it's odd to have two completely different
>>> systems for essentially doing the same thing.
>>
>> I agree, but I don't like much the easy template system. We're basically
>> re-inventing the wheel. Better solutions already exist. Some of them
>> even ship with Emacs.
>>
>> I think the function could replace the template system altogether. It's
>> easy enough to mimic current system with, e.g., Yasnippet.
>
> In that case, would you be more in favor of a keymap-plus-subkey system,
> or a keymap-plus-prompt system?
   ^^
I mean, keybinding-plus-prompt...




Re: [O] function for inserting a block

2017-10-23 Thread Eric Abrahamsen
Nicolas Goaziou  writes:

> Hello,
>
> Eric Abrahamsen  writes:
>
>> Kaushal Modi  writes:
>>
>>> On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:
>>
>> [...]
>>
>>> @Eric: I believe you were sort of onboard with this suggestion, just gated 
>>> by a doubt if this actually can make into master. 
>>
>> In principle yes, I agree it's odd to have two completely different
>> systems for essentially doing the same thing.
>
> I agree, but I don't like much the easy template system. We're basically
> re-inventing the wheel. Better solutions already exist. Some of them
> even ship with Emacs.
>
> I think the function could replace the template system altogether. It's
> easy enough to mimic current system with, e.g., Yasnippet.

In that case, would you be more in favor of a keymap-plus-subkey system,
or a keymap-plus-prompt system?





Re: [O] org-capture quitting and make-capture-frame

2017-10-23 Thread Nicolas Goaziou
Tyler Smith  writes:

> Quitting needs to do something that you can respond to, either with
> a hook, an advised function or something else?

I thought `org-capture-finalize' would be called anyway. But it isn't
the case.

> My proposal was just the first thing that I thought of, I'm sure there
> are better solutions. That could be (message ...), but I'm missing
> something in that case.

You could use

  (condition-case nil
  (progn
(org-capture)
(delete-other-windows))
(error (delete-frame)))

Obviously, this relies on the fact that exiting raises an error.


Regards,



Re: [O] org-capture quitting and make-capture-frame

2017-10-23 Thread Tyler Smith
On Mon, Oct 23, 2017, at 04:03 PM, Nicolas Goaziou wrote:
> 
> Wouldn't it make more sense to turn it into 
> 
>  (message "Abort")
> 
> ? After all, it is not an error. It also allow to call other functions,
> e.g., `delete-frame' after exiting capture.
> 
> WDYT?
> 

I did think it was odd that this called an error, as it isn't an error
at all. 

I'm not sure how calling `(message ...)` at that point would enable
calling `delete-frame` after exiting capture? At the moment I'm calling
`delete` frame it by advising org-capture-destroy and
org-capture-finalize. I don't think either are called when you quit out
of the template selection dialog. Quitting needs to do something that
you can respond to, either with a hook, an advised function or something
else?

My proposal was just the first thing that I thought of, I'm sure there
are better solutions. That could be (message ...), but I'm missing
something in that case.

Best,

Tyler




Re: [O] org-capture quitting and make-capture-frame

2017-10-23 Thread Nicolas Goaziou
Hello,

Tyler Smith  writes:

> Hi,
>
> I use org-capture with a new frame, so I can call it quickly when from
> the OS (see
> http://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml).
>
> This works well, except that if I quit a capture, the frame is left
> hanging. I looked through the code, and this is due to org-capture
> calling `(user-error "Abort")` in response to my entering 'q' to
> indicate I want to cancel my capture. 
>
> It would be nice to allow for some configuration here. In my case, I
> have replaced this line:
>
> ((equal entry "q")
>   (user-error "Abort"))
>
> (source:
> http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/org-capture.el?h=emacs-sync#n632
> )
>
> with
>
> ((equal entry "q")
>(if (equal "capture" (frame-parameter nil 'name))  
>(delete-frame))
>
> That will work for my use case, until org-mode is updated at least.
> Would it be possible to do something like this instead:
>
> ((equal entry "q")
>   (funcall org-capture-quite-function))

Wouldn't it make more sense to turn it into 

 (message "Abort")

? After all, it is not an error. It also allow to call other functions,
e.g., `delete-frame' after exiting capture.

WDYT?

Regards,

-- 
Nicolas Goaziou



Re: [O] function for inserting a block

2017-10-23 Thread Nicolas Goaziou
Hello,

Eric Abrahamsen  writes:

> Kaushal Modi  writes:
>
>> On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:
>
> [...]
>
>> @Eric: I believe you were sort of onboard with this suggestion, just gated 
>> by a doubt if this actually can make into master. 
>
> In principle yes, I agree it's odd to have two completely different
> systems for essentially doing the same thing.

I agree, but I don't like much the easy template system. We're basically
re-inventing the wheel. Better solutions already exist. Some of them
even ship with Emacs.

I think the function could replace the template system altogether. It's
easy enough to mimic current system with, e.g., Yasnippet.

Regards,

-- 
Nicolas Goaziou



Re: [O] function for inserting a block

2017-10-23 Thread Eric Abrahamsen
Kaushal Modi  writes:

> On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:

[...]

> @Eric: I believe you were sort of onboard with this suggestion, just gated by 
> a doubt if this actually can make into master. 

In principle yes, I agree it's odd to have two completely different
systems for essentially doing the same thing.

> So, checking with Nicolas, and the thread if the proposed behavior change 
> with easy templates (only when region is selected) would be accepted. 




[O] org-capture quitting and make-capture-frame

2017-10-23 Thread Tyler Smith
Hi,

I use org-capture with a new frame, so I can call it quickly when from
the OS (see
http://www.windley.com/archives/2010/12/capture_mode_and_emacs.shtml).

This works well, except that if I quit a capture, the frame is left
hanging. I looked through the code, and this is due to org-capture
calling `(user-error "Abort")` in response to my entering 'q' to
indicate I want to cancel my capture. 

It would be nice to allow for some configuration here. In my case, I
have replaced this line:

((equal entry "q")
(user-error "Abort"))

(source:
http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/org-capture.el?h=emacs-sync#n632
)

with

((equal entry "q")
   (if (equal "capture" (frame-parameter nil 'name))  
   (delete-frame))

That will work for my use case, until org-mode is updated at least.
Would it be possible to do something like this instead:

((equal entry "q")
  (funcall org-capture-quite-function))

That would allow you to provide a sensible default, such as '(user-error
"Abort")', while allowing users to tweak this behaviour, as needed for
cleaning up capture frames.

I've pasted the additional functions I'm using below, FYI.

Best,

Tyler

(defun make-capture-frame ()  
  "Create a new frame and run org-capture."  
  (interactive)  
  (select-frame-set-input-focus
   (make-frame '((name . "capture") 
 (width . 120) 
 (height . 15  
  (setq word-wrap 1)
  (setq truncate-lines nil)
  (org-capture))

(defadvice org-switch-to-buffer-other-window 
  (after supress-window-splitting activate)  
  "Delete the extra window if we're in a capture frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
  (delete-other-windows)))

(defadvice org-capture-destroy 
(after delete-capture-frame activate)  
  "Advise capture-destroy to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
  (delete-frame)))

(defadvice org-capture-finalize 
(after delete-capture-frame activate)  
  "Advise capture-finalize to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
  (delete-frame)))
 

-- 
plantarum.ca



Re: [O] function for inserting a block

2017-10-23 Thread Kaushal Modi
On Mon, Oct 23, 2017 at 10:00 AM Carsten Dominik  wrote:

> I am not sure I understand, at least with transient-region turned on.
> Typing 

You're correct.


> Or do you mean to actually put "<" into a keymap?
>

I actually do that in my personal config .. Maybe binding "<" in org keymap
is the simplest way.

I have this function in my config bound to "<":

(defun modi/org-template-maybe ()
  "Insert org-template if point is at the beginning of the line,
or if a region is selected.  Else call `self-insert-command'."
  (interactive)
  (let ((is-region? (use-region-p)))
(if (or is-region?
(and (not is-region?)
 (looking-back "^[[:blank:]]*")))
(hydra-org-template/body) ;Wrapper function for
`org-try-structure-completion'
  (self-insert-command 1
-- 

Kaushal Modi


Re: [O] function for inserting a block

2017-10-23 Thread Carsten Dominik
On Mon, Oct 23, 2017 at 12:52 PM, Kaushal Modi 
wrote:

> On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:
>
>> On Fri, Oct 20, 2017 at 5:15 PM Eric Abrahamsen 
>> wrote:
>>
>>> The template really only inserts the block type, not anything specific
>>> like the source language or export backend.
>>
>>
>> Right, but based on the code you have, you can easily add "SRC org", "SRC
>> emacs-lisp" to the default value of that list. Looking at that, users can
>> also get an idea that they can add their favorite languages to that list
>> too.
>>
>>
>>> I think prompting for
>>> "second-level" information like that might be a little overkill.
>>>
>>
>> I second that. The first-level prompt also feels a bit slow, honestly,
>> compared to using easy templates like "> (just an example) to insert the, well, EXAMPLE block as usual. But *if
>> region is selected*, it does the wrapping as in your code.
>>
>> This is what I mean (GIF animation):
>>
>> https://i.imgur.com/201TISW.gifv
>>
>> I use hydra to provide those awesome hints.. but the same can be done
>> without hydras too.
>>
>
> Hello all,
>
> Above, I suggested merging the template insertion function with the
> current easy template code.
>
> With that, the easy template behavior will remain unchanged if no region
> is selected. But if a region is selected, the same template (example: " Will wrap that region with that template.
>

I Kaustal,

I am not sure I understand, at least with transient-region turned on.
Typing 
> I also have a GIF showing that behavior in action (linked in my previous
> reply).
>
> Benefits:
> - Quicker as there are no prompts.. the user simply types the template
> string as configured by them.
> - Also one doesn't need to do a context switch to use a different binding
> based on if region is selected or not.
>
> @Eric: I believe you were sort of onboard with this suggestion, just gated
> by a doubt if this actually can make into master.
>
> So, checking with Nicolas, and the thread if the proposed behavior change
> with easy templates (only when region is selected) would be accepted.
>
>> --
>
> Kaushal Modi
>


Re: [O] Bug: c++ code block automatically adds comma [8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/)]

2017-10-23 Thread Michal Politowski
On Mon, 23 Oct 2017 12:15:29 +0200, Nicolas Goaziou wrote:
> Hello,
> 
> Michal Politowski  writes:
> 
> > Interesting, even if not very likely to hit anyone, that lines
> > intentionally starting with ,,* are not escaped and thus
> > lose one comma on the next edit.
> 
> Could you provide an ECM?

I mean something like this. I'm new to org and don't know any practical
examples where it matters, but it's interesting.

#+BEGIN_EXAMPLE
  Start editing with C-c ' enter ,* and ,,* at the beginninng of the next two 
lines,
  end end editing with C-c ' - you get two identical lines.
#+END_EXAMPLE

-- 
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.



Re: [O] function for inserting a block

2017-10-23 Thread Kaushal Modi
On Fri, Oct 20, 2017, 5:43 PM Kaushal Modi  wrote:

> On Fri, Oct 20, 2017 at 5:15 PM Eric Abrahamsen 
> wrote:
>
>> The template really only inserts the block type, not anything specific
>> like the source language or export backend.
>
>
> Right, but based on the code you have, you can easily add "SRC org", "SRC
> emacs-lisp" to the default value of that list. Looking at that, users can
> also get an idea that they can add their favorite languages to that list
> too.
>
>
>> I think prompting for
>> "second-level" information like that might be a little overkill.
>>
>
> I second that. The first-level prompt also feels a bit slow, honestly,
> compared to using easy templates like " (just an example) to insert the, well, EXAMPLE block as usual. But *if
> region is selected*, it does the wrapping as in your code.
>
> This is what I mean (GIF animation):
>
> https://i.imgur.com/201TISW.gifv
>
> I use hydra to provide those awesome hints.. but the same can be done
> without hydras too.
>

Hello all,

Above, I suggested merging the template insertion function with the current
easy template code.

With that, the easy template behavior will remain unchanged if no region is
selected. But if a region is selected, the same template (example: " --

Kaushal Modi


Re: [O] Bug: c++ code block automatically adds comma [8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/)]

2017-10-23 Thread Nicolas Goaziou
Hello,

Michal Politowski  writes:

> Interesting, even if not very likely to hit anyone, that lines
> intentionally starting with ,,* are not escaped and thus
> lose one comma on the next edit.

Could you provide an ECM?

Regards,

-- 
Nicolas Goaziou



[O] Bug: Error during evaluation of C source blocks on remote machine [9.1.2 (9.1.2-15-g1d5142-elpa @ c:/Users/Ivan/.emacs.d/elpa/org-20171016/)]

2017-10-23 Thread trus19

Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 http://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


I have org file with C source block. I work with file on Windows PC.
I have linux machine, which is accessible through Putty. For reasons, i
want to evaluate C code blocks there (mostly because it has gcc).

Here is relevant fragment of my org file:

> #+PROPERTY: header-args :noweb yes :results verbatim :dir /pscp:tcl:/home/tc 
> :flags -std=c99
> 
> Ok, time for something more interesting.
> 
> Let's say we want to change 2 values between variables. How to do
> that? As we learned, with pointers, like:
> 
> #+NAME: swap_function
> #+BEGIN_SRC C
>   void swap_int(int* pa, int* pb)
>   {
>   int c = *pa;
>   ,*pa = *pb;
>   ,*pb = c;
>   }
> 
>   #define SWAP(a, b, t) {t temp##t; temp##t = a; a = b; b = temp##t;}
> 
> #+END_SRC
> 
> Trying it out:
> 
> #+BEGIN_SRC C :main no
> 
>   #include 
> 
>   <>
> 
>   void main()
>   {
>   int a = 1, b = 19;
>   printf("Before testing a=%d, b=%d\n", a, b);
>   swap_int(, );
>   printf("After testing function a=%d, b=%d\n", a, b);
>   SWAP(a, b, int);
>   printf("After testing macro a=%d, b=%d\n", a, b);
>   }
> 
> #+END_SRC

However, when i evaluate source block, i get the following error:

> Spawning child process: invalid argument

I have tried to debug the issue. Error is produced by call to

> (write-region start end input-file)

in function org-babel--shell-command-on-region. This supposedly creates
on remote machine file containing user input (actually,
empty). Evaluation does not go to the invocation of compiler command
line, sadly.

How can that be fixed?


Emacs  : GNU Emacs 24.5.1 (x86_64-w64-mingw32)
 of 2016-01-21 on MICROSOFT-PC
Package: Org mode version 9.1.2 (9.1.2-15-g1d5142-elpa @ 
c:/Users/Ivan/.emacs.d/elpa/org-20171016/)

current state:
==
(setq
 org-journal-mode-hook '(#[nil "\301\302\303\304$\207"
   [org-journal-encrypt-on org-add-hook 
org-journal-encryption-hook nil t] 5]
 (lambda nil
  (org-add-hook org-journal-encrypt-on (quote 
org-journal-encryption-hook) nil t))
 )
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe 
org-babel-header-arg-expand)
 org-speed-command-hook '(org-speed-command-activate 
org-babel-speed-command-activate)
 org-occur-hook '(org-first-headline-recenter)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-log-done 'time
 org-confirm-shell-link-function 'yes-or-no-p
 org-agenda-restore-windows-after-quit t
 org-agenda-custom-commands '(("n" "Agenda and all TODO's" ((agenda "") 
(alltodo "")))
  ("d" "Undated tasks" alltodo "" 
((org-agenda-todo-ignore-with-date t
 org-use-sub-superscripts '{}
 org-default-notes-file "c:/Users/Ivan/Dropbox/org/notes.org"
 org-agenda-include-diary t
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-from-is-user-regexp nil
 org-src-mode-hook '(org-src-babel-configure-edit-buffer 
org-src-mode-configure-edit-buffer)
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-babel-pre-tangle-hook '(save-buffer)
 org-mode-hook '((lambda nil (define-key org-mode-map (kbd "C-c f") (quote 
krv/org-toggle-focus)))
 (lambda nil (make-local-variable (quote 
coding-system-for-read))
  (make-local-variable (quote coding-system-for-write))
  (setq coding-system-for-read (quote utf-8-dos)) (setq 
coding-system-for-write (quote utf-8)))
 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-show-block-all append local]
   5 "\n\n(fn)"]
 #[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook org-babel-show-result-all 
append local] 5 "\n\n(fn)"]
 org-babel-result-hide-spec org-babel-hide-all-hashes 
org-journal-update-auto-mode-alist)
 org-refile-targets '((org-agenda-files :maxlevel . 3))
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
ENTRY)"]
 org-outline-path-complete-in-steps nil
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-refile-use-outline-path t
 org-directory "c:/Users/Ivan/Dropbox/org"
 org-enforce-todo-dependencies t
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers 
org-cycle-show-empty-lines
  org-optimize-window-after-visibility-change)
 org-journal-dir "c:/Users/Ivan/Dropbox/org/journal/"
 org-refile-allow-creating-parent-nodes 'confirm
 org-todo-keywords '((sequence "LATER(l)" "TODO(t!)" "CHECK(k!)" "|" "DONE(d)")
 (sequence "HOLD(h@/!)" "|" "CANCELLED(c@/!)"))
 org-agenda-window-setup 

Re: [O] Bug: c++ code block automatically adds comma [8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/)]

2017-10-23 Thread Michal Politowski
On Sun, 22 Oct 2017 19:30:55 +0200, Nicolas Goaziou wrote:
> Hello,
> 
> Louis Strous  writes:
> 
> > When I edit a c++ code block using C-c ' and then finish the edit using
> > C-c ' again, then org-mode sometimes adds a comma to the code.
[...]
> > Note the appearance of a comma in front of the "*".
> >
> > 7. Press "C-c '" to edit the code block again.  The code displayed in
> > the "*Org Src *scratch*[ c++ ]*" buffer does not contain the comma:
> >
> > if (foo)
> >*foo = 3;
> >
> > 8. Press "C-c '" to finish the editing.  The code in the *scratch*
> > buffer still contains the comma.
> >
> > End of reproduction scenario.
> 
> See (info "(org) Literal examples"), fourth footnote

Interesting, even if not very likely to hit anyone, that lines
intentionally starting with ,,* are not escaped and thus
lose one comma on the next edit.

-- 
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.