ledger / ledger-mode

Emacs Lisp files for interacting with the C++Ledger accounting system
GNU General Public License v2.0
377 stars 75 forks source link

Emacs Windows Cygwin - Error in path expansion - Cannot read journal file #261

Open DriXse opened 6 years ago

DriXse commented 6 years ago

Hi,

Unfortunately i must use Microsoft Windows at work without administrator right.

I use emacs ,for everything, with cygwin and ledger i found only here, and all works fine without ledger-mode and org-babel. When i want to have report with block like this

#+BEGIN_SRC ledger :cmdline bal :noweb yes

ledger expand the variable %(ledger-file) incorrectly

ledger -f d\:/cygwin64/tmp/babel-6244Sli/ledger-6244ShV bal

Error: Cannot read journal file "/cygdrive/d/ledger/d:/cygwin64/tmp/babel-6244Sli/ledger-6244ShV"

Apparently, its not a "emacs ledger-mode" problem, but a problem with ledger boost library like report here https://github.com/AlexanderAA/ledger_binaries_windows/issues/3 Do you know a solution ? A way to make ledger works with Cygwin ?

Thanks a lot !

yiufung commented 6 years ago

Under that issue, @ngleb has provided a gist that works for me. Try it, then put it in your $PATH, or use (setq ledger-binary-path "path/to/ledger.exe")

denysos commented 5 years ago

I have found a way to use ledger with Emacs Ledger mode on windows 10 without the "cygdrive" issue

I have noticed when you try to use ledger with the command line, cd C:\path\to\ledger\file this doesn't work : ledger -f C:\path\to\ledger\file\test.ledger bal I get : Error: Cannot read journal file "/cygdrive/c/Users/denis/Desktop/ledger/C:\Users\denis\Desktop\ledger\test.ledger"

but this is right : ledger -f test.ledger bal

      -2500 cred  706 revenu:salaire:travail
        650 cred  assets
       -350 cred    cash
       1000 cred    current
       1850 cred  expenses
       1000 cred    cadeau
        350 cred    habits
        500 cred    ship:gas

               0

So to make it work, we have to send to ledger a file name without a path. I have found "ledger-master-file" in ledger-report.el

(defun ledger-master-file ()
  "Return the master file for a ledger file.

   The master file is either the file for the current ledger buffer or the
   file specified by the buffer-local variable `ledger-master-file'.  Typically
   this variable would be set in a file local variable comment block at the
   end of a ledger file which is included in some other file."
  (if ledger-master-file
      (expand-file-name ledger-master-file)
    (buffer-file-name)))

if the variable "ledger-master-file" is not set, buffer-file-name is sent to ledger, and it has at path ...

so I've changed to :

 (defun ledger-master-file ()
  "Return the master file for a ledger file.

   The master file is either the file for the current ledger buffer or the
   file specified by the buffer-local variable `ledger-master-file'.  Typically
   this variable would be set in a file local variable comment block at the
   end of a ledger file which is included in some other file."
  (if ledger-master-file
      (expand-file-name ledger-master-file)
    (file-name-nondirectory (buffer-file-name))))

with file-name-nondirectory to get rid of the path in the file name .... And it works !

I have to take this defun into account just before using ledger, it doesn't work if I set it in my .emacs

enderw88 commented 5 years ago

I think this is an issue with your installation. This will break on *nix based systems.

On Thu, Feb 28, 2019 at 3:56 AM denysos notifications@github.com wrote:

I have found a way to use ledger with Emacs Ledger mode on windows 10 without the "cygdrive" issue

I have noticed when you try to use ledger with the command line, cd C:\path\to\ledger\file this doesn't work : ledger -f C:\path\to\ledger\file\test.ledger bal I get : Error: Cannot read journal file "/cygdrive/c/Users/denis/Desktop/ledger/C:\Users\denis\Desktop\ledger\test.ledger"

but this is right : ledger -f test.ledger bal

  -2500 cred  706 revenu:salaire:travail
    650 cred  assets
   -350 cred    cash
   1000 cred    current
   1850 cred  expenses
   1000 cred    cadeau
    350 cred    habits
    500 cred    ship:gas

           0

So to make it work, we have to send to ledger a file name without a path. I have found "ledger-master-file" in ledger-report.el

(defun ledger-master-file () "Return the master file for a ledger file.

The master file is either the file for the current ledger buffer or the file specified by the buffer-local variable `ledger-master-file'. Typically this variable would be set in a file local variable comment block at the end of a ledger file which is included in some other file." (if ledger-master-file (expand-file-name ledger-master-file) (buffer-file-name)))

if the variable "ledger-master-file" is not set, buffer-file-name is sent to ledger, and it has at path ...

so I've changed to :

(defun ledger-master-file () "Return the master file for a ledger file.

The master file is either the file for the current ledger buffer or the file specified by the buffer-local variable `ledger-master-file'. Typically this variable would be set in a file local variable comment block at the end of a ledger file which is included in some other file." (if ledger-master-file (expand-file-name ledger-master-file) (file-name-nondirectory (buffer-file-name))))

with file-name-nondirectory to get rid of the path in the file name .... And it works !

I have to take this defun into account just before using ledger, it doesn't work if I set it in my .emacs

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ledger/ledger/issues/555#issuecomment-468229682, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1rLPzshqbOxCpeHe0UsuVZewmTMXukks5vR7XtgaJpZM4TBsVx .

-- Craig, Corona De Tucson, AZ [image: missile_flyout] enderw88.wordpress.com

denysos commented 5 years ago

@enderw88 yes but Ledger with Emacs on Windows is the subject of this issue ...

enderw88 commented 5 years ago

I should have been clearer. This is not a bug in ledger-mode.

On Fri, Mar 1, 2019 at 01:13 denysos notifications@github.com wrote:

@enderw88 https://github.com/enderw88 yes but Ledger with Emacs on Windows is the subject of this issue ...

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/ledger/ledger/issues/555#issuecomment-468581171, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1rLFq_knrRb0Yr96TVk4Dq2Mm6bePWks5vSOE_gaJpZM4TBsVx .

-- Craig, Corona De Tucson, AZ [image: missile_flyout] enderw88.wordpress.com

denysos commented 5 years ago

of course it's just a workaround for windows users ... just to wait until a fix for this issue.

doolio commented 8 months ago

I should have been clearer. This is not a bug in ledger-mode.

@enderw88 OK, then shall we consider this issue closed?