yilkalargaw / org-auto-tangle

a simple emacs package to allow org file tangling upon save
BSD 2-Clause "Simplified" License
137 stars 15 forks source link

Tangling over ssh #28

Open barslmn opened 8 months ago

barslmn commented 8 months ago

Hi, thanks for the great package.

I got the following block:

#+begin_src python :tangle /ssh:g5:/mnt/e/epi25/WES/migren/get_intervar_and_format_table.py
import pandas as pd
pairs = {
"a": {'SAMPLE': 'Sample', 'Location': 'Location'},
"b": {'SYMBOL': 'Symbol', 'Consequence': 'Consequence'},
"c": { "EXON": 'Exon',"INTRON":'Intron' },
"d": { "HGVSc": 'HGVSc',"HGVSp": 'HGVSp' },
"e": { "Existing_variation": 'Existing variation',"MAX_AF": 'Frequency' },
"f": { "AD": 'Allele depth',"GT": 'Genotype' },
"g": { "Criteria": 'Criteria','Intervar':"Classification" },
}
def format_df(df):
.
.
.
#+end_src

I can tangle this with the org-bable-tangle command. But org-auto-tangle gives the following error:

error in process sentinel: async-when-done: Opening output file: No such file or directory, /ssh:g5:/mnt/e/epi25/WES/migren/.#get_intervar_and_format_table.py
error in process sentinel: Opening output file: No such file or directory, /ssh:g5:/mnt/e/epi25/WES/migren/.#get_intervar_and_format_table.py

org-auto-tangle: 0.6.0 GNU Emacs v29.1 nil Doom core v3.0.0-pre HEAD -> master 03d692f1 2023-12-08 15:11:45 -0500 Doom modules v23.12.0-pre HEAD -> master 03d692f1 2023-12-08 15:11:45 -0500

whhone commented 6 months ago

I hit the same issue. Going deeper, org-auto-tangle uses async-start to tangle asynchronously. This starts a new Emacs process that does not know the existing ssh connection.

I can think of two ways to fix it

  1. teach the child Emacs process to use the existing ssh connection, like ,(async-inject-variables "tramp-ssh-controlmaster-options")
  2. use make-thread so that everything happens in the same process.

I did not get (1) to work but can get (2) working. Here is the rewritten version. One cons it that it might freeze the UI like usual org-babel-tangle.

  (defun org-auto-tangle-async (file)
    "Invoke `org-babel-tangle-file' asynchronously on FILE."
    (message "Tangling %s..." (buffer-file-name))
    (make-thread
     (let* ((buf-vars (plist-get (org-auto-tangle--get-inbuffer-options)
                                 :with-vars))
            (with-vars (if buf-vars
                           (mapcar #'intern
                                   (org-uniquify (org-split-string
                                                  (symbol-name buf-vars) ":")))
                         org-auto-tangle-with-vars))
            (preserved (mapcar (lambda (v)
                                 (cons v (symbol-value v)))
                               (append '(org-src-preserve-indentation
                                         org-babel-pre-tangle-hook
                                         org-babel-post-tangle-hook)
                                       with-vars)))
            (evaluate (not (member file org-auto-tangle-babel-safelist))))
       (let ((start-time (current-time))
             (non-essential t)
             (org-confirm-babel-evaluate evaluate))
         (cl-progv (mapcar #'car preserved) (mapcar #'cdr preserved)
           (org-babel-tangle-file file))

         (let ((tangle-time (float-time (time-since start-time)))
               (message-string (format "Tangling %S completed after" file)))
           (message "%s %.2f seconds" message-string tangle-time))))))