emacs hangs on viewing pdf

1.7k views Asked by At

When I view a pdf in emacs in the default version(emacs -Q), the doc-view works perfectly. But in the customized version of my emacs, opening even the smallest of PDFs hangs the emacs. What can be the possible reason for this?

EDIT: I used bisection and found that the linum-mode is producing problems. Once I put that off, the docs are opening correctly without any delay whatsoever. Is there any way to off the linum-mode for doc-view mode?

EDIT: It is higly unorganised, but I'm posting my .emacs here.

;C-x C-q read only mode enabled or disabled

;FULL SCREEN ON STARTUP START

(defun fullscreen ()
       (interactive)
       (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                 '(2 "_NET_WM_STATE_FULLSCREEN" 0)))
(fullscreen)


(setq initial-scratch-message "rough buffer.")
(global-visual-line-mode t)

;needed so that emacs knows how to display dvi(basically binary file generated by latex which is then converted to pdf) files.Device Independent file format
;C-c C-v to generate PDF

(setq inhibit-splash-screen 0)
(global-linum-mode t)

;C++ CUSTOMIZATIONS

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))    ;.h files are treated as c files instaed of c++ in emacs. Remove it!

(require 'cl)

(defun file-in-directory-list-p (file dirlist)
  "Returns true if the file specified is contained within one of
the directories in the list. The directories must also exist."
  (let ((dirs (mapcar 'expand-file-name dirlist))
        (filedir (expand-file-name (file-name-directory file))))
    (and
     (file-directory-p filedir)
     (member-if (lambda (x) ; Check directory prefix matches
                  (string-match (substring x 0 (min(length filedir) (length x))) filedir))
                dirs))))

(defun buffer-standard-include-p ()
  "Returns true if the current buffer is contained within one of
the directories in the INCLUDE environment variable."
  (and (getenv "INCLUDE")
       (file-in-directory-list-p buffer-file-name (split-string (getenv "INCLUDE") path-separator))))

(add-to-list 'magic-fallback-mode-alist '(buffer-standard-include-p . c++-mode))


;indentation customization(replacing tabs by 4 spaces)
(setq-default c-basic-offset 4
                  tab-width 4
                  indent-tabs-mode t)

;Indentating the curly braces(the braces don't indent with the inner code)
 (setq c-default-style "linux"
          c-basic-offset 4)

;handling uncommon file extensions
 (add-to-list 'auto-mode-alist '("\\.ext\\'" . c-mode))

;C++ CUSTOMIZATIONS END
(show-paren-mode 1) ;highlighting matching parenthses
(global-font-lock-mode 1)


(defun delete-selected-region ()
  "delete selected region"
  (interactive)
  (delete-region (point) (mark)))

(global-set-key (kbd "C-z") 'delete-selected-region)

;SELECTED REGION DELETION USING  C-Z (THIS ALSO HELPS TO PREVENT ACCIDENTAL ICONIFICATION OF EMACS DUE TO C-Z) END

(show-paren-mode 1) ;highlighting matching parenthses
(transient-mark-mode t)
(global-font-lock-mode 1)
;LINE DUPLICATION USING C-d START

(defun line-duplicate ()
  "line-duplication"
  (interactive)
  (setq position (point))
  (command-execute (kbd "C-a C-k C-k C-y C-y"))
  (goto-char position)
)

(global-set-key (kbd "C-M-d") 'line-duplicate)

;can also simply use 
;(global-set-key "\C-d" "\C-S-BACKSPACE\C-y\C-y")

;LINE DUPLICATION USING C-d END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;images display

;; -- laoding images in org mode
;; enable image mode first
(setq-default iimage-mode t)


;Splitted window switching with C-TAB

(global-set-key (kbd "<C-escape>") 'other-window)
;     

;hiding code(hiding the contents of a function)C-c @ C-h and C-c @ C-s

(add-hook 'c-mode-common-hook #'hs-minor-mode)
(add-hook 'c++-mode-common-hook #'hs-minor-mode)
(add-hook 'java-mode-common-hook #'hs-minor-mode)


;(setq-default hs-minor-mode 1)
(global-set-key (kbd "C-c C-h") (kbd "C-c @ C-h"))         ;;hiding block of code
(global-set-key (kbd "C-c C-r") (kbd "C-c @ C-s"))         ;;revealing block of code


;black screen
(invert-face 'default)


;removing the ststus line
;(setq-default mode-line-format nil)
;(insert-image (create-image "~/car.jpg"))

(setq-default fill-column 72)
(setq auto-fill-mode 1)
(setq major-mode 'text-mode)

 ;No backup files
(setq make-backup-files nil)



(blink-cursor-mode -1)
(set-scroll-bar-mode 'right)

;disables scroll bar
;(if (fboundp 'scroll-bar-mode) (scroll-bar-mode 1))


(auto-image-file-mode 1)


(setq hippie-expand-try-functions-list
      '(;try-expand-all-abbrevs
    yas/hippie-try-expand
    try-complete-file-name
    try-expand-list
    ;; FIXME this function is causing unexpected point movement.
    ;; try-expand-dabbrev-visible
    try-expand-dabbrev-all-buffers
    try-expand-dabbrev-from-kill
    try-complete-lisp-symbol-partially
    try-complete-lisp-symbol
    try-expand-all-abbrevs
    ))

;disabling tool bar
(tool-bar-mode -1)
(put 'upcase-region 'disabled nil)





;Qt customizations

(make-face 'qt-keywords-face)
  (set-face-foreground 'qt-keywords-face "BlueViolet")
  (font-lock-add-keywords 'c++-mode '(("\\<Q_OBJECT\\>" . 'qt-keywords-face)))
  (font-lock-add-keywords 'c++-mode '(("\\<SIGNAL\\|SLOT\\>" . 'qt-keywords-face)))
  (font-lock-add-keywords 'c++-mode '(("\\<Q[A-Z3][A-Za-z0-9]*" . 'qt-keywords-face)))

(setq auto-mode-alist (cons '("\\.pro$" . makefile-mode) auto-mode-alist))


;

;hideshow: hide initial blocks of comments
(load-library "hideshow")
(add-hook 'c++-mode-hook       (lambda () (hs-minor-mode 1)) )
(add-hook 'c-mode-hook         (lambda () (hs-minor-mode 1)) )
(add-hook 'makefile-mode-hook  (lambda () (hs-minor-mode 1)) )
(add-hook 'css-mode-hook       (lambda () (hs-minor-mode 1)) )
(add-hook 'java-mode-hook       (lambda () (hs-minor-mode 1)) )
(add-hook 'python-mode-hook       (lambda () (hs-minor-mode 1)) )
(add-hook 'sh-mode-hook       (lambda () (hs-minor-mode 1)) )
(setq hs-minor-mode-hook  'hs-hide-initial-comment-block)


;

;cool theme visit by M-x color-theme-select
;(color-theme-robin-hood)

;(set-face-background 'font-lock-comment-face "red")

;(require 'color-theme)
;(color-theme-initialize)
;(color-theme-whateveryouwant)

(set-background-color "black")
(set-border-color "white")

(setq font-lock-maximum-decoration t)


;; ;FONT SIZE

 (set-face-attribute 'default nil :height 86)

;; ;FONT SIZE
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;miscellaneous
(setq max-mini-window-height .25)
(which-function-mode)




;the perfect terminal ansi-term
;(desktop-save-mode

;a couple of productivity incrementers
(defalias 'rs 'replace-string)
(defalias 'qr 'query-replace)
(defalias 'rr 'replace-regexp)
(defalias 'yes-or-no-p 'y-or-n-p) ; y or n is enough
(defalias 'qrr 'query-replace-regexp)
(defalias 'g 'goto-line)
(defalias 'bd 'bookmark-delete)
(defalias 'acm 'auto-complete-mode)
(defalias 'hsa 'hs-show-all)
(defalias 'hha 'hs-hide-all)
(defalias 'sb 'speedbar)
(defalias 'gfr 'gtags-find-rtag)

;(setq TEXpdf-mode t)
;(add-hook 'doc-view-mode-hook 'auto-revert-mode)
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
 '(custom-enabled-themes (quote (wheatgrass)))
 '(custom-safe-themes (quote ("de4403b9a108d38f35a1717b43a8ebe40410dd44b6324e3bc1adfdb658a8004c" default))))

;insert date using emacs
(defun insertdate ()
  (interactive)
  (insert (format-time-string "%d-%m-%Y")))
(global-set-key [(f5)] 'insertdate)



(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)


(load-file "~/.emacs.d/bufferSwitch.el")

(defun encrypt ()
  (interactive)
  (epa-encrypt-region (point-min) (point-max) nil nil nil)
)

(global-set-key (kbd "C-c C-e") 'encrypt)


(defun decrypt ()
  (interactive)
  (epa-decrypt-region (point-min) (point-max))
)

(global-set-key (kbd "C-c C-d") 'decrypt)



(defun terminal-come ()
  (interactive)
  (command-execute (kbd "C-x 2 ESC 14 C-x ^ C-<escape>"))
  (if (equal (get-buffer "*ansi-term*") nil) (command-execute (kbd "M-x ansi-term RET")) (switch-to-buffer "*ansi-term*"))
)
(global-set-key (kbd "C-x C-c") 'terminal-come)



(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)


(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)


;; 1- if remove-if is not found, add here (require 'cl)
 ;; 2- in my emacs 23, I had to remove the "b" from "lambda (b)"

(require 'cl)
 (when (require 'tabbar nil t)
   (setq tabbar-buffer-groups-function
         (lambda (b) (list "All Buffers")))
   (setq tabbar-buffer-list-function
         (lambda ()
           (remove-if
            (lambda(buffer)
              (find (aref (buffer-name buffer) 0) " *"))
            (buffer-list))))
   (tabbar-mode))

 (setq tabbar-buffer-groups-function
          (lambda ()
            (list "All")))
(require 'tabbar)
(tabbar-mode 1)
(global-set-key [(C-S-iso-lefttab)] 'tabbar-backward)
(global-set-key (kbd "C-<tab>") 'tabbar-forward)

(load-file "~/.emacs.d/commoncppfunctions.el")

(set-face-attribute 'default nil :height 94)

(add-hook 'asm-mode-set-comment-hook
'(lambda ()
(setq asm-comment-char ?#)))



(menu-bar-mode -1)
;(setq mode-line-format nil)

;bookmarks
(global-set-key (kbd "C-c C-z") 'bookmark-set)
(global-set-key (kbd "C-c C-a") 'bookmark-jump)
(global-set-key (kbd "C-c C-q") 'bookmark-delete)
(global-set-key (kbd "C-`") 'shell-command)
(global-set-key (kbd "C-!") 'gtags-pop-stack)

(defadvice bookmark-jump (after bookmark-jump activate)
  (let ((latest (bookmark-get-bookmark bookmark)))
    (setq bookmark-alist (delq latest bookmark-alist))
    (add-to-list 'bookmark-alist latest)))

(display-time-mode 1)

;highlighting  todo,fixme, bug

(add-hook 'prog-mode-common-hook
               (lambda ()
                (font-lock-add-keywords nil
                 '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))

(setq load-path (cons ".emacs.d/" load-path))
(autoload 'gtags-mode "gtags" "" t)

(setq term-default-bg-color "#000000")
(setq term-default-fg-color "#7cfc00")

(add-hook 'prog-mode-hook (lambda () (gtags-mode 1)))
(scroll-bar-mode -1)


(defun auto-recompile-emacs-file ()
  (interactive)
  (when (and buffer-file-name (string-match "\\.emacs" buffer-file-name))
    (let ((byte-file (concat buffer-file-name "\\.elc")))
      (if (or (not (file-exists-p byte-file))
              (file-newer-than-file-p buffer-file-name byte-file))
          (byte-compile-file buffer-file-name)))))

(add-hook 'after-save-hook 'auto-recompile-emacs-file)

(require 'color-theme)
(color-theme-initialize)
;(setq color-theme-is-global t)
;(color-theme-arjen)


;don't you fiddle with this. this is added by custom, if reused, in another syatem, this might have to be deleted.
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "black" :foreground "green" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 90 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))
 '(compilation-info ((((class color) (min-colors 88) (background dark)) (:foreground "red" :weight bold))))
 '(cursor ((t (:background "red"))))
 '(custom-comment ((((class grayscale color) (background dark)) (:background "dim gray" :height 110))))
 '(custom-state ((((class color) (background dark)) (:foreground "pink1"))))
 '(font-lock-comment-delimiter-face ((default (:inherit font-lock-comment-face :height 97)) (((class color) (min-colors 16)) nil)))
 '(font-lock-comment-face ((((class color) (min-colors 88) (background dark)) (:foreground "chocolate1" :height 90))))
 '(font-lock-function-name-face ((((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue" :height 96))))
 '(font-lock-preprocessor-face ((t (:inherit font-lock-builtin-face :weight semi-bold))))
 '(font-lock-string-face ((((class color) (min-colors 88) (background dark)) (:foreground "LightSalmon" :height 97))))
 '(font-lock-variable-name-face ((((class color) (min-colors 89)) (:foreground "midnight blue"))))
 '(highlight ((((class color) (min-colors 89)) (:background "azure3" :foreground "white"))))
 '(ido-only-match ((((class color)) (:foreground "khaki4"))))
 '(mode-line ((((class color) (min-colors 88)) (:background "red" :foreground "black" :box (:line-width -1 :color "blue" :style released-button)))))
 '(region ((((class color) (min-colors 89)) (:background "sienna4" :foreground "white"))))
 '(tool-bar ((default (:foreground "black" :box (:line-width 3 :style released-button))) (((type x w32 ns) (class color)) (:background "blue")))))

(set-face-foreground 'default "green")
(column-number-mode)
2

There are 2 answers

0
lawlist On BEST ANSWER
(add-hook 'doc-view-mode-hook
  (lambda ()
    (linum-mode -1)
  ))
0
Drew On

The answer to "What in my init file is causing problems?" is simple: Bisect your init file recursively until you find which sexp is the culprit.

People can easily be misled into thinking this is inefficient or dumb. It is neither. Yes, it is blind. But acting on hunches is often worse than acting blindly: misconceptions, bad assumptions.

If you need to remind yourself of the power of binary search (which is what this is), remember the story of the sage who asked to be paid with a grain of rice on the first chessboard square, double that on the second square, double that on the third square... It takes no time at all to narrow your init file to the offending expression.

To bisect it, you can do one of the following:

  • Comment a section (1/2, then 3/4, then 7/8,...): M-x comment-region is your friend. And with C-u it uncomments.

  • M-x eval-region

Just try it. It takes less time than you think.