Commit 98620504 authored by Göktuğ Kayaalp's avatar Göktuğ Kayaalp

emacs: import pdf-tools server, upgrade pdf-tools

parent de59fe34
No preview for this file type
EMACS ?= emacs
# Handle the mess when inside Emacs.
unexport INSIDE_EMACS #cask not like this.
ifeq ($(EMACS), t)
EMACS = emacs
endif
emacs = $(EMACS)
emacs_version = $(shell $(emacs) --batch --eval \
'(princ (format "%s.%s" emacs-major-version emacs-minor-version))')
$(info Using Emacs $(emacs_version))
version=$(shell sed -ne 's/^;\+ *Version: *\([0-9.]\)/\1/p' lisp/pdf-tools.el)
pkgname=pdf-tools-$(version)
pkgfile=$(pkgname).tar
.PHONY: all clean distclean bytecompile test check melpa cask-install
all: $(pkgfile)
# Create a elpa package including the server
$(pkgfile): .cask/$(emacs_version) server/epdfinfo lisp/*.el
cask package .
# Compile the Lisp sources
bytecompile: .cask/$(emacs_version)
cask exec $(emacs) --batch -L lisp -f batch-byte-compile lisp/*.el
# Run ERT tests
test: all
PACKAGE_TAR=$(pkgfile) cask exec ert-runner
check: test
# Run the autobuild script tests in docker
test-autobuild: server-test
# Run all tests
test-all: test test-autobuild
# Init cask
.cask/$(emacs_version):
cask install
# Run the autobuild script (installing depends and compiling)
autobuild:
cd server && ./autobuild
# Soon to be obsolete targets
melpa-build: autobuild
cp build/epdfinfo .
install-server-deps: ;
# Create a package like melpa would.
melpa-package: $(pkgfile)
cp $(pkgfile) $(pkgname)-melpa.tar
tar -u --transform='s/server/$(pkgname)\/build\/server/' \
-f $(pkgname)-melpa.tar \
$$(git ls-files server)
tar -u --transform='s/Makefile/$(pkgname)\/build\/Makefile/' \
-f $(pkgname)-melpa.tar \
Makefile
tar -u --transform='s/README\.org/$(pkgname)\/README/' \
-f $(pkgname)-melpa.tar \
README.org
-tar --delete $(pkgname)/epdfinfo \
-f $(pkgname)-melpa.tar
# Various clean targets
clean: server-clean
rm -f -- $(pkgfile)
rm -f -- lisp/*.elc
rm -f -- pdf-tools-readme.txt
rm -f -- pdf-tools-$(version).entry
distclean: clean server-distclean
rm -rf -- .cask
# Server targets
server/epdfinfo: server/Makefile server/*.[ch]
$(MAKE) -C server
server/Makefile: server/configure
cd server && ./configure -q
server/configure: server/configure.ac
cd server && ./autogen.sh
server-test: server/Makefile
$(MAKE) -C server check
server-clean:
! [ -f server/Makefile ] || $(MAKE) -C server clean
server-distclean:
! [ -f server/Makefile ] || $(MAKE) -C server distclean
This diff is collapsed.
......@@ -207,21 +207,16 @@ width MAX-WIDTH and `eql' hash value.
Remember that image was recently used.
Returns nil, if no matching image was found."
(let ((cache (cons nil pdf-cache--image-cache))
(let ((cache pdf-cache--image-cache)
image)
;; Find it in the cache and remove it. We need to find the
;; element in front of it.
(while (and (cdr cache)
;; Find it in the cache.
(while (and (setq image (pop cache))
(not (pdf-cache--image-match
(car (cdr cache))
page min-width max-width hash)))
(setq cache (cdr cache)))
(setq image (cadr cache))
(when (car cache)
(setcdr cache (cddr cache)))
;; Now push it at the front.
image page min-width max-width hash))))
;; Remove it and push it to the front.
(when image
(push image pdf-cache--image-cache)
(setq pdf-cache--image-cache
(cons image (delq image pdf-cache--image-cache)))
(pdf-cache--image/data image))))
(defun pdf-cache-put-image (page width data &optional hash)
......
......@@ -50,6 +50,10 @@ command `pdf-sync-minor-mode' is activated and this map is defined."
:group 'pdf-sync
:type 'key-sequence)
(make-obsolete-variable
'pdf-sync-forward-display-pdf-key
"Bound in Auctex's to C-c C-v, if TeX-source-correlate-mode is activate." "1.0")
(defcustom pdf-sync-backward-hook nil
"Hook ran after going to a source location.
......@@ -132,19 +136,6 @@ with AUCTeX."
nil nil nil
(pdf-util-assert-pdf-buffer))
(eval-after-load "tex"
'(when (and pdf-sync-forward-display-pdf-key
(boundp 'TeX-source-correlate-map)
(let ((key (lookup-key
TeX-source-correlate-map
(kbd pdf-sync-forward-display-pdf-key))))
(or (null key)
(numberp key))))
(define-key TeX-source-correlate-map
(kbd pdf-sync-forward-display-pdf-key)
'pdf-sync-forward-search)))
;; * ================================================================== *
;; * Backward search (PDF -> TeX)
......@@ -786,50 +777,5 @@ The first such filename is returned, or nil if none was found."
beg (point-min))
(goto-char beg)))))))))
;; * ================================================================== *
;; * Compatibility
;; * ================================================================== *
;;;###autoload
(define-obsolete-variable-alias
'pdf-sync-tex-display-pdf-key
'pdf-sync-forward-display-pdf-key nil)
;;;###autoload
(define-obsolete-variable-alias
'pdf-sync-goto-tex-hook
'pdf-sync-backward-hook nil)
;;;###autoload
(define-obsolete-variable-alias
'pdf-sync-display-pdf-hook
'pdf-sync-forward-hook nil)
;;;###autoload
(define-obsolete-variable-alias
'pdf-sync-display-pdf-action
'pdf-sync-forward-display-action nil)
(define-obsolete-function-alias
'pdf-sync-mouse-goto-tex
'pdf-sync-backward-search-mouse)
(define-obsolete-function-alias
'pdf-sync-goto-tex
'pdf-sync-backward-search)
(define-obsolete-function-alias
'pdf-sync-correlate-tex
'pdf-sync-backward-correlate)
(define-obsolete-function-alias
'pdf-sync-display-pdf
'pdf-sync-forward-search)
(define-obsolete-function-alias
'pdf-sync-correlate-pdf
'pdf-sync-forward-correlate)
(provide 'pdf-sync)
;;; pdf-sync.el ends here
......@@ -789,7 +789,7 @@ AWINDOW is deleted."
(setq newwin (window--display-buffer
buf
(split-window-below height)
'window alist display-buffer-mark-dedicated))
'window alist))
(pdf-util-window-attach newwin window)
newwin))
......
......@@ -373,6 +373,9 @@ PNG images in Emacs buffers."
(setq-local revert-buffer-function #'pdf-view-revert-buffer)
;; No auto-save at the moment.
(setq-local buffer-auto-save-file-name nil)
;; Disable image rescaling.
(when (boundp 'image-scaling-factor)
(setq-local image-scaling-factor 1))
;; No undo at the moment.
(unless buffer-undo-list
(buffer-disable-undo))
......
*.o
.deps/
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
config.h
config.h.in
config.log
config.status
configure
depcomp
epdfinfo
install-sh
libsynctex.a
missing
stamp-h1
ar-lib
compile
config.h.in~
.clang_complete
callgrind.out.*
config.guess
config.sub
TAGS
bin_PROGRAMS = epdfinfo
epdfinfo_CFLAGS = -Wall $(glib_CFLAGS) $(poppler_glib_CFLAGS) $(poppler_CFLAGS) \
$(png_CFLAGS)
epdfinfo_CXXFLAGS = -Wall $(epdfinfo_CFLAGS)
epdfinfo_LDADD = $(glib_LIBS) $(poppler_glib_LIBS) $(poppler_LIBS) \
$(png_LIBS) libsynctex.a $(zlib_LIBS)
epdfinfo_SOURCES = epdfinfo.c epdfinfo.h poppler-hack.cc
noinst_LIBRARIES = libsynctex.a
libsynctex_a_SOURCES = synctex_parser.c synctex_parser_utils.c synctex_parser.h \
synctex_parser_local.h synctex_parser_utils.h
libsynctex_a_CFLAGS = -w $(zlib_CFLAGS)
if HAVE_W32
epdfinfo_LDADD += -lshlwapi
endif
SYNCTEX_UPSTREAM = svn://tug.org/texlive/tags/texlive-2017.1/Build/source/texk/web2c/synctexdir
SYNCTEX_FILES = synctex_parser.c \
synctex_parser.h \
synctex_parser_local.h \
synctex_parser_readme.txt \
synctex_parser_utils.c \
synctex_parser_utils.h \
synctex_parser_version.txt
check-local:
@if $(MAKE) --version 2>&1 | grep -q GNU; then \
cd test && $(MAKE) $(AM_MAKEFLAGS); \
else \
echo "Skipping tests in server/test (requires GNU make)"; \
fi
synctex-pull:
@if [ -n "$$(git status --porcelain)" ]; then \
git status; \
echo "Not checking-out files into a dirty work-directory"; \
false; \
fi
for file in $(SYNCTEX_FILES); do \
svn export --force $(SYNCTEX_UPSTREAM)/$$file; \
done
This diff is collapsed.
#!/bin/sh
echo "Running autoreconf..."
autoreconf -i
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([epdfinfo], 1.0, [politza@fh-trier.de])
AM_INIT_AUTOMAKE([-Wall -Wno-override foreign silent-rules])
AC_CONFIG_SRCDIR([epdfinfo.h])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_RANLIB
AM_PROG_AR
# Checks for libraries.
HAVE_POPPLER_FIND_OPTS="no (requires poppler-glib >= 0.22)"
HAVE_POPPLER_ANNOT_WRITE="no (requires poppler-glib >= 0.19.4)"
HAVE_POPPLER_ANNOT_MARKUP="no (requires poppler-glib >= 0.26)"
PKG_CHECK_MODULES([png], [libpng])
PKG_CHECK_MODULES([glib], [glib-2.0])
PKG_CHECK_MODULES([poppler], [poppler])
PKG_CHECK_MODULES([poppler_glib], [poppler-glib >= 0.16.0])
PKG_CHECK_EXISTS([poppler-glib >= 0.19.4], [HAVE_POPPLER_ANNOT_WRITE=yes])
PKG_CHECK_EXISTS([poppler-glib >= 0.22], [HAVE_POPPLER_FIND_OPTS=yes])
PKG_CHECK_EXISTS([poppler-glib >= 0.26], [HAVE_POPPLER_ANNOT_MARKUP=yes])
PKG_CHECK_MODULES([zlib], [zlib])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#ifndef _WIN32
error
#endif
]])], [have_w32=true], [have_w32=false])
AM_CONDITIONAL(HAVE_W32, [test "$have_w32" = true])
if test "$have_w32" = true; then
if test "$MSYSTEM" = MINGW32 -o "$MSYSTEM" = MINGW64; then
# glib won't work properly on msys2 without it.
CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $CFLAGS"
fi
fi
SAVED_CPPFLAGS=$CPPFLAGS
CPPFLAGS=$poppler_CFLAGS
AC_LANG_PUSH([C++])
# Check if we can use the -std=c++11 option.
m4_include([m4/ax_check_compile_flag.m4])
AX_CHECK_COMPILE_FLAG([-std=c++11], [HAVE_STD_CXX11=yes])
if test "$HAVE_STD_CXX11" = yes; then
CXXFLAGS="-std=c++11 $CXXFLAGS"
fi
# Check for private poppler header.
AC_CHECK_HEADERS([Annot.h PDFDocEncoding.h], [],
AC_MSG_ERROR([cannot find necessary poppler-private header (see README.org)]))
AC_LANG_POP([C++])
CPPFLAGS=$SAVED_CPPFLAGS
# Setup compile time features.
if test "$HAVE_POPPLER_FIND_OPTS" = yes; then
AC_DEFINE([HAVE_POPPLER_FIND_OPTS],1,
[Define to 1 to enable case sensitive searching (requires poppler-glib >= 0.22).])
fi
if test "$HAVE_POPPLER_ANNOT_WRITE" = yes; then
AC_DEFINE([HAVE_POPPLER_ANNOT_WRITE],1,
[Define to 1 to enable writing of annotations (requires poppler-glib >= 0.19.4).])
fi
if test "$HAVE_POPPLER_ANNOT_MARKUP" = yes; then
AC_DEFINE([HAVE_POPPLER_ANNOT_MARKUP],1,
[Define to 1 to enable adding of markup annotations (requires poppler-glib >= 0.26).])
fi
AC_CANONICAL_HOST
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h strings.h err.h])
AC_MSG_CHECKING([for error.h])
SAVED_CFLAGS=$CFLAGS
CFLAGS="$poppler_CFLAGS $poppler_glib_CFLAGS"
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <error.h>
],[error (0, 0, "");])],
[AC_DEFINE([HAVE_ERROR_H],1, [Define to 1 if error.h is useable.])
AC_MSG_RESULT([yes])],
AC_MSG_RESULT([no]))
AC_LANG_POP([C])
CFLAGS=$SAVED_CFLAGS
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_CHECK_TYPES([ptrdiff_t])
AC_C_BIGENDIAN
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_STRTOD
AC_CHECK_FUNCS([strcspn strtol getline])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
echo
echo "Is case-sensitive searching enabled ? ${HAVE_POPPLER_FIND_OPTS}"
echo "Is modifying text annotations enabled ? ${HAVE_POPPLER_ANNOT_WRITE}"
echo "Is modifying markup annotations enabled ? ${HAVE_POPPLER_ANNOT_MARKUP}"
echo
This diff is collapsed.
// Copyright (C) 2013, 2014 Andreas Politz
// Author: Andreas Politz <politza@fh-trier.de>
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _EPDF_H_
#define _EPDF_H_ _EPDF_H_
#include "config.h"
#include <glib.h>
#include <poppler.h>
#include <png.h>
/* Some library functions print warnings to stdout, inhibit it. */
#define DISCARD_STDOUT(saved_fd) \
do { \
int __fd; \
fflush(stdout); \
saved_fd = dup(1); \
__fd = open("/dev/null", O_WRONLY); \
dup2(__fd, 1); \
close(__fd); \
} while (0)
#define UNDISCARD_STDOUT(saved_fd) \
do { \
fflush(stdout); \
dup2(saved_fd, 1); \
close(saved_fd); \
} while (0)
/* Writing responses */
#define OK_BEGIN() \
do { \
puts("OK"); \
} while (0)
#define OK_END() \
do { \
puts("."); \
fflush (stdout); \
} while (0)
#define OK() \
do { \
puts ("OK\n."); \
fflush (stdout); \
} while (0)
/* Dealing with image data. */
#ifdef WORDS_BIGENDIAN
#define ARGB_TO_RGB(rgb, argb) \
do { \
rgb[0] = argb[1]; \
rgb[1] = argb[2]; \
rgb[2] = argb[3]; \
} while (0)
#define ARGB_EQUAL(argb1, argb2) \
(argb1[1] == argb2[1] \
&& argb1[2] == argb2[2] \
&& argb1[3] == argb2[3])
#else
#define ARGB_TO_RGB(rgb, argb) \
do { \
rgb[0] = argb[2]; \
rgb[1] = argb[1]; \
rgb[2] = argb[0]; \
} while (0)
#define ARGB_EQUAL(argb1, argb2) \
(argb1[0] == argb2[0] \
&& argb1[1] == argb2[1] \
&& argb1[2] == argb2[2])
#endif
#define NORMALIZE_PAGE_ARG(doc, first, last) \
*first = MAX(1, *first); \
if (*last <= 0) \
*last = poppler_document_get_n_pages (doc); \
else \
*last = MIN(*last, poppler_document_get_n_pages (doc));
/* png_jmpbuf is supposed to be not available in older versions of
libpng. */
#ifndef png_jmpbuf
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#endif
#ifndef HAVE_ERROR_H
# define error(status, errno, fmt, args...) \
do { \
int error = (errno); \
fflush (stdout); \
fprintf (stderr, "%s: " fmt, PACKAGE_NAME, ## args); \
if (error) \
fprintf (stderr, ": %s", strerror (error)); \
fprintf (stderr, "\n"); \
exit (status); \
} while (0)
#endif
#define internal_error(fmt, args...) \
error (2, 0, "internal error in %s: " fmt, __func__, ## args)
#define error_if_not(expr) \
if (! (expr)) goto error;
#define perror_if_not(expr, fmt, args...) \
do { \
if (! (expr)) \
{ \
printf_error_response ((fmt), ## args); \
goto error; \
} \
} while (0)
#define cerror_if_not(expr, error_msg, fmt, args...) \
do { \
if (! (expr)) \
{ \
if (error_msg) \
*(error_msg) = g_strdup_printf((fmt), ## args); \
goto error; \
} \
} while (0)
/* Declare commands */
#define DEC_CMD(name) \
{#name, cmd_ ## name, cmd_ ## name ## _spec, \
G_N_ELEMENTS (cmd_ ## name ## _spec)}
#define DEC_CMD2(command, name) \
{name, cmd_ ## command, cmd_ ## command ## _spec, \
G_N_ELEMENTS (cmd_ ## command ## _spec)}
/* Declare option */
#define DEC_DOPT(name, type, sname) \
{name, type, offsetof (document_options_t, sname)}
enum suffix_char { NONE, COLON, NEWLINE};
enum image_type { PPM, PNG };
typedef struct
{
PopplerAnnotMapping *amap;
gchar *key;
} annotation_t;
typedef enum
{
ARG_INVALID = 0,
ARG_DOC,
ARG_BOOL,
ARG_STRING,
ARG_NONEMPTY_STRING,
ARG_NATNUM,
ARG_EDGE,
ARG_EDGE_OR_NEGATIVE,
ARG_EDGES,
ARG_EDGES_OR_POSITION,
ARG_COLOR,
ARG_REST
} command_arg_type_t;
typedef struct
{
const char *name;
command_arg_type_t type;
size_t offset;
} document_option_t;
typedef struct
{
PopplerColor bg, fg;
gboolean usecolors;
gboolean printed;
} render_options_t;
typedef struct
{
render_options_t render;
} document_options_t;
typedef struct
{
PopplerDocument *pdf;
char *filename;
char *passwd;
struct
{
GHashTable *keys; /* key => page */
GList **pages; /* page array */
} annotations;
document_options_t options;
} document_t;
typedef struct
{
command_arg_type_t type;
union
{
gboolean flag;
const char *string;
long natnum;
document_t *doc;
gdouble edge;
PopplerColor color;
PopplerRectangle rectangle;
#ifdef HAVE_POPPLER_ANNOT_MARKUP
PopplerQuadrilateral quadrilateral;
#endif
struct
{
char * const *args;
int nargs;
} rest;
} value;
} command_arg_t;
typedef struct
{
GHashTable *documents;
} epdfinfo_t;
typedef struct
{
const char *name;
void (* execute) (const epdfinfo_t *ctxt, const command_arg_t *args);
const command_arg_type_t *args_spec;
int nargs;
} command_t;
/* Defined in poppler-hack.cc */
#ifdef HAVE_POPPLER_ANNOT_WRITE
extern void xpoppler_annot_set_rectangle (PopplerAnnot*, PopplerRectangle*);
#endif
extern gchar *xpoppler_annot_markup_get_created (PopplerAnnotMarkup*);
#endif /* _EPDF_H_ */
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the current language's compiler
# or gives an error. (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the current language's default
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
# force the compiler to issue an error when a bad flag is given.
#
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General