From 60622f12cc3e3b0fed952d594fa0b9fc35028fe0 Mon Sep 17 00:00:00 2001 From: magic_rb Date: Mon, 16 Oct 2023 14:57:43 +0200 Subject: [PATCH] Add hledger to omen Signed-off-by: magic_rb --- emacs-lisp/hledger.org | 45 +++++++++++++++++ flake.nix | 1 + .../modules/emacs/.emacs.d/org/base.org | 29 ----------- home-manager/modules/emacs/default.nix | 2 + nixos/systems/omen/nixpkgs.nix | 1 + overlays/ledger-compat/default.nix | 7 +++ overlays/ledger-compat/ledger.sh | 50 +++++++++++++++++++ 7 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 emacs-lisp/hledger.org create mode 100644 overlays/ledger-compat/default.nix create mode 100644 overlays/ledger-compat/ledger.sh diff --git a/emacs-lisp/hledger.org b/emacs-lisp/hledger.org new file mode 100644 index 0000000..87f16fd --- /dev/null +++ b/emacs-lisp/hledger.org @@ -0,0 +1,45 @@ +:PROPERTIES: +:header-args:emacs-lisp: :comments link :results none +:ID: 2f95ff8f-b030-4c90-8296-29c1cc8b2b0c +:END: +#+title: HLedger +#+filetags: emacs-load + +For hledger, it's possible to use =ledger-mode= instead of =hledger-mode=. We'll see how it goes. It does require some convincing though. + +#+begin_src emacs-lisp + (use-package ledger-mode + :straight t + :config + (setq ledger-binary-path "ledger-hledger") + (setq ledger-default-date-format ledger-iso-date-format) + (setq ledger-report-links-in-register nil) + (setq ledger-report-native-highlighting-arguments '("--color=always")) + (setq ledger-report-auto-width nil) + (setq ledger-reconcile-default-commodity "EUR") + (setq ledger-report-use-header-line t) + (setq ledger-report-use-native-highlighting t) + (setq ledger-report-auto-refresh-sticky-cursor t) + (setq ledger-report-use-strict t) + (setq ledger-highlight-xact-under-point t) + (setq ledger-copy-transaction-insert-blank-line-after t) + (add-to-list 'auto-mode-alist '("\\.\\(h?ledger\\|journal\\|j\\)$" . ledger-mode)) + (setq ledger-report-balance + (list "bal" (concat ledger-binary-path " --strict -f %(ledger-file) bal"))) + + (setq ledger-report-reg + (list "reg" (concat ledger-binary-path " --strict -f %(ledger-file) reg"))) + + (setq ledger-report-payee + (list "payee" (concat ledger-binary-path " --strict -f %(ledger-file) reg @%(payee)"))) + + (setq ledger-report-account + (list "account" (concat ledger-binary-path " --strict -f %(ledger-file) reg %(account)"))) + + (setq ledger-reports + (list ledger-report-balance + ledger-report-reg + ledger-report-payee + ledger-report-account))) +#+end_src + diff --git a/flake.nix b/flake.nix index a3b2abc..d99b34f 100644 --- a/flake.nix +++ b/flake.nix @@ -104,6 +104,7 @@ overlays/virtiofsd-zfs overlays/show-files-to-be-deleted overlays/rolling_datasets + overlays/ledger-compat inputs.uterranix.flakeModule ]; diff --git a/home-manager/modules/emacs/.emacs.d/org/base.org b/home-manager/modules/emacs/.emacs.d/org/base.org index ce3e85b..ebaf4db 100644 --- a/home-manager/modules/emacs/.emacs.d/org/base.org +++ b/home-manager/modules/emacs/.emacs.d/org/base.org @@ -215,35 +215,6 @@ and work with it. :hook (lsp-after-open-hook lsp-origami-try-enable)) #+END_SRC -* hledger - -For hledger, it's possible to use =ledger-mode= instead of =hledger-mode=. We'll see how it goes. It does require some convincing though. - -#+BEGIN_SRC emacs-lisp - (use-package ledger-mode - :straight t - :config - (setq ledger-binary-path "hledger") - (setq ledger-mode-should-check-version nil) - (add-to-list 'auto-mode-alist '("\\.\\(h?ledger\\|journal\\|j\\)$" . ledger-mode)) - (setq ledger-report-balance - (list "bal" (concat ledger-binary-path " --strict -f %(ledger-file) bal"))) - - (setq ledger-report-reg - (list "reg" (concat ledger-binary-path " --strict -f %(ledger-file) reg"))) - - (setq ledger-report-payee - (list "payee" (concat ledger-binary-path " --strict -f %(ledger-file) reg @%(payee)"))) - - (setq ledger-report-account - (list "account" (concat ledger-binary-path " --strict -f %(ledger-file) reg %(account)"))) - - (setq ledger-reports - (list ledger-report-balance - ledger-report-reg - ledger-report-payee - ledger-report-account))) -#+END_SRC * Projectile diff --git a/home-manager/modules/emacs/default.nix b/home-manager/modules/emacs/default.nix index cfd6670..b59cc4b 100644 --- a/home-manager/modules/emacs/default.nix +++ b/home-manager/modules/emacs/default.nix @@ -72,6 +72,8 @@ isync imagemagick texlive.combined.scheme-full + ledger-compat + hledger ]; }; }; diff --git a/nixos/systems/omen/nixpkgs.nix b/nixos/systems/omen/nixpkgs.nix index 53136e3..3cf3542 100644 --- a/nixos/systems/omen/nixpkgs.nix +++ b/nixos/systems/omen/nixpkgs.nix @@ -14,6 +14,7 @@ emacs-master-nativecomp rolling_datasets virtiofsd-zfs + ledger-compat ]) ++ (with inputs'.nixng.overlays; [ diff --git a/overlays/ledger-compat/default.nix b/overlays/ledger-compat/default.nix new file mode 100644 index 0000000..6227949 --- /dev/null +++ b/overlays/ledger-compat/default.nix @@ -0,0 +1,7 @@ +{ inputs, ... }: +{ + flake.overlays.ledger-compat = + final: prev: { + ledger-compat = prev.writeShellScriptBin "ledger-hledger" (builtins.readFile ./ledger.sh); + }; +} diff --git a/overlays/ledger-compat/ledger.sh b/overlays/ledger-compat/ledger.sh new file mode 100644 index 0000000..60ee2d7 --- /dev/null +++ b/overlays/ledger-compat/ledger.sh @@ -0,0 +1,50 @@ +# -*- mode: shell-script -*- + +iargs=("$@") +oargs=() +j=0; +date=; +for((i=0; i<${#iargs[@]}; ++i)); do + case ${iargs[i]} in + --date-format) + # drop --date-format and the next arg + i=$((i+1)); + ;; + --sort) + # drop --sort and the next arg + i=$((i+1)); + ;; + --limit) + # drop --limit and the next arg + i=$((i+1)); + ;; + --collapse) + # drop --collapse and the next arg + i=$((i+1)); + ;; + --uncleared) + oargs[j]="-UP"; + j=$((j+1)) + ;; + xact) + # convert "xact" to "print --match" + oargs[j]=print; oargs[j+1]=--match; j=$((j+2)); + # drop xact argument and stash the date argument + i=$((i+1)); + date=${iargs[i]}; + ;; + *) + # keep any other args: + oargs[j]=${iargs[i]}; + j=$((j+1)); + ;; + esac +done + +if test "$date" +then + # substitute the given date for the old date: + hledger "${oargs[@]}" | sed "1s/....-..-../$date/" +else + hledger "${oargs[@]}" +fi