jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
275 stars 58 forks source link

Cannot send org-babel plot with org-msg (wrong file directory) #63

Closed averter closed 4 years ago

averter commented 4 years ago

I am trying to send an email with the org-msg+mu4e combo which contains some source code and a plot figure. The MWE below returns the correct file path for an output file when run in an org-mode file

#+begin_src python :results file :exports none
  import matplotlib, numpy
  matplotlib.use('Agg')
  import matplotlib.pyplot as plt
  fig=plt.figure(figsize=(4,2))
  x=numpy.linspace(-15,15)
  plt.plot(numpy.sin(x)/x)
  fig.tight_layout()
  plt.savefig('/home/username/python-matplot-fig.png')
  return '/home/username/python-matplot-fig.png' # return filename to org-mode
#+end_src

However, when I run it on org-msg the resulting file does not exist and the directory is incorrect, like so

#+RESULTS:
[[file:../../../python-matplot-fig.png]]

I would expect for the file path to be my home directory, as shown in this video by Mike Zamansky. My configuration of org-msg is the default one, as suggested in the main webpage.

Other info

(setq org-export-use-babel t
      org-export-with-toc nil)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((shell . t)
   (ruby . t)
   (awk . t)
   (matlab .t)
   (org . t)
   (python . t)
   (latex . t)
   (ditaa . t)
   (C . t)))

(org-link-set-parameters
 "run"
 :follow #'org-babel-ref-resolve)
(setq org-confirm-babel-evaluate (defun my-org-confirm-babel-evaluate (lang body)
                   (not (string= lang "matlab"))))  ; don't ask for matlab

(setq org-export-with-broken-links t)   ; otherwise html wont export

(require 'org-tempo)            ; sometimes org-babel breaks and this solution helps 
jeremy-compostella commented 4 years ago

Hi @averter,

I tried to reproduce your issue but I could not.

If I copy-paste your python babel block I and then I hit C-c C-c from inside it does create the image with the appropriate path and the following gets added to the org msg buffer (I change the path to /tmp but it should not make any difference).

#+RESULTS:
[[file:/tmp/python-matplot-fig.png]]

Note that if you want the image to be included in the email you have to change the :exports none to :exports results.

Regards, Jeremy

averter commented 4 years ago

Thanks @jeremy-compostella, I've tried to comment all of my org-mode configuration except org-babel and test this again, but I get the same result. I've also changed the directory to /tmp and set :exports results as you suggested. I'm running out of ideas/tests to run.

averter commented 4 years ago

Finally found what the problem was. This is at the very top of my .emacs file

;; MELPA controls
(when (>= emacs-major-version 24)  
  (require 'package)
  (setq package-archives
    '(("melpa" . "https://melpa.org/packages/")
      ("gnu" . "https://elpa.gnu.org/packages/")
      ;; ("org" . "http://orgmode.org/elpa/")
      ))
  (package-initialize))

(note the commented line of org-mode from elpa). So I believe that I was experiencing conflicts between the org-mode version from git and the pre-packaged org-mode version that comes with emacs by default. Now everything works as expected. Thanks for your help.