summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/packages/emacs-xyz.scm49
-rw-r--r--gnu/packages/patches/emacs-doc-toc-shell-commands.patch252
3 files changed, 302 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index e604f37d242..b273dae61c1 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1217,6 +1217,7 @@ dist_patch_DATA = \
1217 %D%/packages/patches/emacs-all-the-icons-remove-duplicate-rs.patch \ 1217 %D%/packages/patches/emacs-all-the-icons-remove-duplicate-rs.patch \
1218 %D%/packages/patches/emacs-deferred-fix-number-of-arguments.patch \ 1218 %D%/packages/patches/emacs-deferred-fix-number-of-arguments.patch \
1219 %D%/packages/patches/emacs-disable-jit-compilation.patch \ 1219 %D%/packages/patches/emacs-disable-jit-compilation.patch \
1220 %D%/packages/patches/emacs-doc-toc-shell-commands.patch \
1220 %D%/packages/patches/emacs-elisp-autofmt-fix-region-send.patch \ 1221 %D%/packages/patches/emacs-elisp-autofmt-fix-region-send.patch \
1221 %D%/packages/patches/emacs-exec-path.patch \ 1222 %D%/packages/patches/emacs-exec-path.patch \
1222 %D%/packages/patches/emacs-fix-scheme-indent-function.patch \ 1223 %D%/packages/patches/emacs-fix-scheme-indent-function.patch \
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 1eb844ee709..343ff79c517 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -233,6 +233,7 @@
233 #:use-module (gnu packages julia-xyz) 233 #:use-module (gnu packages julia-xyz)
234 #:use-module (gnu packages ncurses) 234 #:use-module (gnu packages ncurses)
235 #:use-module (gnu packages networking) 235 #:use-module (gnu packages networking)
236 #:use-module (gnu packages ocr)
236 #:use-module (gnu packages python) 237 #:use-module (gnu packages python)
237 #:use-module (gnu packages python-xyz) 238 #:use-module (gnu packages python-xyz)
238 #:use-module (gnu packages python-check) 239 #:use-module (gnu packages python-check)
@@ -7752,6 +7753,54 @@ with more precise location control.")
7752 (home-page "https://github.com/fuxialexander/org-pdftools/") 7753 (home-page "https://github.com/fuxialexander/org-pdftools/")
7753 (license license:gpl3+)))) 7754 (license license:gpl3+))))
7754 7755
7756(define-public emacs-doc-toc
7757 (package
7758 (name "emacs-doc-toc")
7759 (version "1.02")
7760 (source (origin
7761 (method git-fetch)
7762 (uri (git-reference
7763 (url "https://github.com/dalanicolai/doc-tools-toc")
7764 (commit "4a179fbacd7bc9efbd6cfcdc8772d42935e6de29")))
7765 (sha256
7766 (base32
7767 "10w0gybhmx9g7qs5kmg7gsz156kndwzzpfhyb7l0p1cghgqii7l4"))
7768 (patches
7769 (search-patches "emacs-doc-toc-shell-commands.patch"))))
7770 (build-system emacs-build-system)
7771 (arguments
7772 (list
7773 #:tests? #f ; no tests
7774 #:phases
7775 #~(modify-phases %standard-phases
7776 (add-after 'unpack 'patch-exec-paths
7777 (lambda* (#:key inputs #:allow-other-keys)
7778 (emacs-substitute-variables "doc-toc.el"
7779 ("doc-toc--ddjvu-program" (search-input-file inputs "/bin/ddjvu"))
7780 ("doc-toc--djvused-program" (search-input-file inputs "/bin/djvused"))
7781 ("doc-toc--djvutxt-program" (search-input-file inputs "/bin/djvutxt"))
7782 ("doc-toc--mutool-program" (search-input-file inputs "/bin/mutool"))
7783 ("doc-toc--pdftocgen-program" (search-input-file inputs "/bin/pdftocgen"))
7784 ("doc-toc--pdftocio-program" (search-input-file inputs "/bin/pdftocio"))
7785 ("doc-toc--pdftotext-program" (search-input-file inputs "/bin/pdftotext"))
7786 ("doc-toc--pdfxmeta-program" (search-input-file inputs "/bin/pdfxmeta"))
7787 ("doc-toc--tesseract-program" (search-input-file inputs "/bin/tesseract"))))))))
7788 (inputs
7789 (list djvulibre
7790 fntsample ; for pdfoutline
7791 mupdf
7792 pdf-tocgen
7793 poppler
7794 tesseract-ocr))
7795 (home-page "https://github.com/dalanicolai/doc-tools-toc")
7796 (synopsis "Manage outlines/table of contents of pdf and djvu documents")
7797 (description "This package provides a multistep process to infer or
7798manually enter an outline for a given pdf or djvu document and to add it to
7799said document, or to edit a pre-existing outline. Outlines can be created
7800manually, automatically generated from a textual table of contents, or
7801generated from typesetting metadata.")
7802 (license license:gpl3+)))
7803
7755(define-public emacs-sage-shell-mode 7804(define-public emacs-sage-shell-mode
7756 (let ((commit "4291700e981a2105d55fa56382ba25046d3d268d") 7805 (let ((commit "4291700e981a2105d55fa56382ba25046d3d268d")
7757 (revision "1")) 7806 (revision "1"))
diff --git a/gnu/packages/patches/emacs-doc-toc-shell-commands.patch b/gnu/packages/patches/emacs-doc-toc-shell-commands.patch
new file mode 100644
index 00000000000..0c10db7e253
--- /dev/null
+++ b/gnu/packages/patches/emacs-doc-toc-shell-commands.patch
@@ -0,0 +1,252 @@
1Upstream-status: https://github.com/dalanicolai/doc-tools-toc/pull/4
2
3diff --git a/doc-toc.el b/doc-toc.el
4index 8b7057c..64eca03 100644
5--- a/doc-toc.el
6+++ b/doc-toc.el
7@@ -216,6 +216,7 @@
8 (defvar pdf-filename)
9
10 (declare-function pdf-cache-get-image "pdf-cache")
11+(declare-function pdf-view-active-region-text "pdf-view")
12 (declare-function pdf-view-goto-page "pdf-view")
13 (declare-function pdf-view-next-page "pdf-view")
14 (declare-function pdf-view-previous-page "pdf-view")
15@@ -262,39 +263,60 @@ URL`http://handyoutlinerfo.sourceforge.net/'."
16 String (i.e. surround with double quotes)."
17 :type 'file)
18
19+(defvar doc-toc--ddjvu-program (executable-find "ddjvu"))
20+(defvar doc-toc--djvused-program (executable-find "djvused"))
21+(defvar doc-toc--djvutxt-program (executable-find "djvutxt"))
22+(defvar doc-toc--mutool-program (executable-find "mutool"))
23+(defvar doc-toc--pdfoutline-program (executable-find "pdfoutline"))
24+(defvar doc-toc--pdftocgen-program (executable-find "pdftocgen"))
25+(defvar doc-toc--pdftocio-program (executable-find "pdftocio"))
26+(defvar doc-toc--pdftotext-program (executable-find "pdftotext"))
27+(defvar doc-toc--pdfxmeta-program (executable-find "pdfxmeta"))
28+(defvar doc-toc--tesseract-program (executable-find "tesseract"))
29+
30+(defun doc-toc--process-to-string (program &rest args)
31+ "Return the output of running PROGRAM with ARGS.
32+
33+Like `shell-command-to-string', but PROGRAM and ARGS are provided as
34+separate strings rather than a single space-separated, escaped string."
35+ (with-temp-buffer
36+ (apply #'call-process
37+ program
38+ nil
39+ (list (current-buffer) nil)
40+ nil
41+ args)
42+ (buffer-string)))
43+
44 ;;;; pdf.tocgen
45 ;;;###autoload
46 (defun doc-toc-gen-set-level (level)
47- "Define the text properties of the heading level.
48-In a pdf-view buffer select a single word in the headline of a
49-certain level. Then run `doc-toc-gen-set-level' to write the text
50+ "define the text properties of the heading level.
51+in a pdf-view buffer select a single word in the headline of a
52+certain level. then run `doc-toc-gen-set-level' to write the text
53 properties to the recipe.toml file that is created in the
54-document's directory. You will be prompted to enter the LEVEL
55-number. The highest level should have number 1, the next level
56+document's directory. you will be prompted to enter the level
57+number. the highest level should have number 1, the next level
58 number 2 etc."
59- (interactive "nWhich level you are setting (number): ")
60+ (interactive "nwhich level you are setting (number): ")
61 (let* ((page (pdf-view-current-page))
62 (filename (url-filename (url-generic-parse-url buffer-file-name)))
63- (pdfxmeta-result (shell-command
64- (format "pdfxmeta --auto %s --page %s %s \"%s\" >> recipe.toml"
65- level
66- page
67- (shell-quote-argument filename)
68- (car (pdf-view-active-region-text))))))
69- ;; (pdfxmeta-result (call-process "pdfxmeta" nil "recipe.toml" nil
70- ;; "--auto" (number-to-string level)
71- ;; "--page" (number-to-string page)
72- ;; (shell-quote-argument filename)
73- ;; (concat "\"" (car (pdf-view-active-region-text)) "\""))))
74+ (pdfxmeta-result (call-process doc-toc--pdfxmeta-program nil "recipe.toml" nil
75+ "--auto" (number-to-string level)
76+ "--page" (number-to-string page)
77+ (shell-quote-argument filename)
78+ (concat "\"" (car (pdf-view-active-region-text)) "\""))))
79 (when (eq pdfxmeta-result 1)
80- (let ((page-text (shell-command-to-string
81- (format "mutool draw -F text %s %s"
82- (shell-quote-argument filename)
83- page
84- ))))
85+ (let ((page-text (doc-toc--process-to-string
86+ doc-toc--mutool-program
87+ "draw"
88+ "-f"
89+ "text"
90+ filename
91+ page)))
92 (pop-to-buffer "page-text")
93 (insert
94- "COULD NOT SET HEADING LEVEL. MUPDF EXTRACTED FOLLOWING PAGE TEXT FROM PAGE:\n")
95+ "could not set heading level. mupdf extracted following page text from page:\n")
96 (add-text-properties 1 (point) '(face font-lock-warning-face))
97 (let ((beg (point)))
98 (insert "(try to select partial word)\n\n")
99@@ -312,8 +334,11 @@ be used after the headline text properties have been defined with
100 the function `doc-toc-gen-set-level'"
101 (interactive)
102 (let ((filename buffer-file-name)
103- (toc (shell-command-to-string
104- (format "pdftocgen %s < recipe.toml" (shell-quote-argument buffer-file-name)))))
105+ (toc (doc-toc--process-to-string
106+ doc-toc--pdftocgen-program
107+ buffer-file-name
108+ "-r"
109+ "recipe.toml")))
110 (switch-to-buffer "toc")
111 (doc-toc-pdftocgen-mode) ;; required before setting local variable
112 (when (fboundp 'flyspell-mode)
113@@ -328,7 +353,8 @@ named output.pdf and opened in a new buffer. Don't forget to
114 rename this new file."
115 (interactive)
116 (let* ((output-buf (get-buffer-create "*pdftocio-output*")))
117- (call-process-region (point-min) (point-max) "pdftocio"
118+ (call-process-region (point-min) (point-max)
119+ doc-toc--pdftocio-program
120 nil output-buf nil pdf-filename)
121 (kill-buffer-if-not-modified (find-file pdf-filename))
122 (when (file-exists-p (concat (file-name-base pdf-filename) "_out.pdf"))
123@@ -483,14 +509,19 @@ ARG (\\[universal-argument]) to enter different separators."
124 (default-process-coding-system
125 (cond ((string= ".pdf" ext)'(windows-1252-unix . utf-8-unix))
126 ((string= ".djvu" ext) '(utf-8-unix . utf-8-unix))))
127- (shell-command (cond ((string= ".pdf" ext) "pdftotext -f %s -l %s -layout %s -")
128- ((string= ".djvu" ext) "djvutxt --page=%s-%s %s")
129- (t (error "Buffer-filename does not have pdf or djvu extension"))))
130- (text (shell-command-to-string
131- (format shell-command
132- startpage
133- endpage
134- (shell-quote-argument buffer-file-name))))
135+ (text (cond ((string= ".pdf" ext)
136+ (doc-toc--process-to-string
137+ doc-toc--pdftotext-program
138+ "-f" startpage
139+ "-l" endpage
140+ "-layout" buffer-file-name
141+ "-"))
142+ ((string= ".djvu" ext)
143+ (doc-toc--process-to-string
144+ doc-toc--djvutxt-program
145+ (format "--page=%s-%s" startpage endpage)
146+ buffer-file-name))
147+ (t (error "Buffer-filename does not have pdf or djvu extension"))))
148 (buffer (get-buffer-create (file-name-sans-extension (buffer-name)))))
149 (switch-to-buffer buffer)
150 (doc-toc-cleanup-mode) ;; required before setting local variable
151@@ -522,7 +553,8 @@ For use in `doc-toc-ocr-languages'."
152 (let ((print-length nil))
153 (message (format "%s" (seq-subseq
154 (split-string
155- (shell-command-to-string "tesseract --list-langs"))
156+ (doc-toc--process-to-string doc-toc--tesseract-program
157+ "--list-langs"))
158 5)))))
159
160 ;;;###autoload
161@@ -557,7 +589,8 @@ unprocessed text."
162 ((string= ".djvu" ext)
163 ;; new code for djvu3
164 (let ((outfile (format "/tmp/pageimagep%s" page)))
165- (shell-command (format "ddjvu -page=%s '%s' %s"
166+ (shell-command (format "%s -page=%s '%s' %s"
167+ doc-toc--ddjvu-program
168 page
169 buffer-file-name
170 outfile))
171@@ -569,8 +602,12 @@ unprocessed text."
172 ;; (number-to-string page)
173 ;; (image-property djvu-doc-image :data))))))
174 (apply #'call-process
175- (append (list "tesseract" nil (list buffer nil) nil file)
176- args))
177+ doc-toc--tesseract-program
178+ nil
179+ (list buffer nil)
180+ nil
181+ file
182+ args)
183 (setq page (1+ page))))
184 (switch-to-buffer buffer)
185 (doc-toc-cleanup-mode) ;; required before setting local variable
186@@ -587,14 +624,20 @@ unprocessed text."
187 (interactive)
188 (let* ((source-buffer (current-buffer))
189 (ext (url-file-extension (buffer-file-name (current-buffer))))
190- (shell-command (cond ((string= ".pdf" ext) (if (executable-find "mutool")
191- "mutool show %s outline"
192- "mutool command is not found"))
193- ((string= ".djvu" ext) "djvused -e 'print-outline' %s")
194- (t (error "Buffer-filename does not have pdf or djvu extension"))))
195- (text (shell-command-to-string
196- (format shell-command
197- (shell-quote-argument buffer-file-name))))
198+
199+ (text (cond ((string= ".pdf" ext)
200+ (unless doc-toc--mutool-program
201+ (error "Command mutool is not found"))
202+ (doc-toc--process-to-string doc-toc--mutool-program
203+ "show"
204+ buffer-file-name
205+ "outline"))
206+ ((string= ".djvu" ext)
207+ (doc-toc--process-to-string doc-toc--djvused-program
208+ "-e"
209+ "print-outline"
210+ buffer-file-name))
211+ (t (error "Buffer-filename does not have pdf or djvu extension"))))
212 (buffer (get-buffer-create (concat (file-name-sans-extension (buffer-name)) ".txt"))))
213 (switch-to-buffer buffer)
214 (setq-local doc-buffer source-buffer)
215@@ -628,7 +671,7 @@ Prompt for startpage and endpage and print OCR output to new buffer."
216 nil
217 (number-to-string page)
218 (image-property djvu-doc-image :data))))))
219- (apply #'call-process "tesseract" nil (list buffer nil) nil
220+ (apply #'call-process doc-toc--tesseract-program nil (list buffer nil) nil
221 file args)
222 (setq page (1+ page))))
223 (switch-to-buffer buffer)))))
224@@ -992,7 +1035,7 @@ to `pdfoutline' shell command."
225 This command uses the shell program `pdfoutline'."
226 (interactive)
227 (save-buffer)
228- (call-process "pdfoutline" nil "*pdfoutline*" nil
229+ (call-process doc-toc--pdfoutline-program nil "*pdfoutline*" nil
230 (concat (file-name-sans-extension (buffer-name)) ".pdf")
231 (buffer-name)
232 (if doc-toc-replace-original-file
233@@ -1009,12 +1052,13 @@ This command uses the shell program `djvused'."
234 (buffer-name)
235 (shell-quote-argument
236 (concat (file-name-sans-extension (buffer-name)) ".djvu"))))
237- (shell-command-to-string
238- (format
239- "djvused -s -e \"set-outline '%s'\" %s"
240- (buffer-name)
241- (shell-quote-argument
242- (concat (file-name-sans-extension (buffer-name)) ".djvu")))))
243+ (doc-toc--process-to-string
244+ doc-toc--djvused-program
245+ "-s"
246+ "-e"
247+ (format "set-outline '%s'"
248+ (buffer-name)) ;; TODO: maybe escape?
249+ (concat (file-name-sans-extension (buffer-name)) ".djvu")))
250
251
252 (defun doc-toc--add-to-doc ()