Skip to main content
added 90 characters in body
Source Link
John Kitchin
  • 12.1k
  • 1
  • 23
  • 45

You probably want something like this. I think you need a function that matches the img, so you can get the region and remove flyspell overlays. Also you need to modify the add-hook call a bit.

(setq x-gtk-use-system-tooltips nil)

(defvar image-tooltip-re (concat  "\\\\includegraphics{\\(?1:.*\\."
                  (regexp-opt '("png" "PNG" "JPG" "jpeg"
                        "jpg" "JPEG" "eps" "EPS" "pdf"))
                  "\\)}")
  "Regexp to match included images")


(defun image-tooltip (window object position)
  (save-excursion
    (goto-char position)
    (let (beg end imgfile img s)
      (while (not (looking-at image-tooltip-re))
        (forward-char -1))
      (setq imgfile (match-string-no-properties 1))
      (if (file-exists-p imgfile)
      (progn
        (setq img (create-image (expand-file-name imgfile)
                    'imagemagick nil :width 800))
        (message (propertize "Look in the minibuffer"
                 'display img)))
    "No file found"))))

(defun img-match (limit)
  "Match bar in at the end of a word."
  (when (re-search-forward image-tooltip-re limit t)
    (flyspell-delete-region-overlays (match-beginning 1)
                     (match-end 1))
    t))

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '((img-match 1 '(face font-lock-keyword-face
                   help-echo image-tooltip))))))

You probably want something like this. I think you need a function that matches the img, so you can get the region and remove flyspell overlays. Also you need to modify the add-hook call a bit.

(setq x-gtk-use-system-tooltips nil)

(defvar image-tooltip-re (concat  "\\\\includegraphics{\\(?1:.*\\."
                  (regexp-opt '("png" "PNG" "JPG" "jpeg"
                        "jpg" "JPEG" "eps" "EPS" "pdf"))
                  "\\)}")
  "Regexp to match included images")


(defun image-tooltip (window object position)
  (save-excursion
    (goto-char position)
    (let (beg end imgfile img s)
      (while (not (looking-at image-tooltip-re))
        (forward-char -1))
      (setq imgfile (match-string-no-properties 1))
      (if (file-exists-p imgfile)
      (progn
        (setq img (create-image (expand-file-name imgfile)
                    'imagemagick nil :width 800))
        (propertize "Look in the minibuffer"
            'display img))
    "No file found"))))

(defun img-match (limit)
  "Match bar in at the end of a word."
  (when (re-search-forward image-tooltip-re limit t)
    (flyspell-delete-region-overlays (match-beginning 1)
                     (match-end 1))
    t))

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '((img-match 1 '(face font-lock-keyword-face
                   help-echo image-tooltip))))))

You probably want something like this. I think you need a function that matches the img, so you can get the region and remove flyspell overlays. Also you need to modify the add-hook call a bit.

(setq x-gtk-use-system-tooltips nil)

(defvar image-tooltip-re (concat  "\\\\includegraphics{\\(?1:.*\\."
                  (regexp-opt '("png" "PNG" "JPG" "jpeg"
                        "jpg" "JPEG" "eps" "EPS" "pdf"))
                  "\\)}")
  "Regexp to match included images")


(defun image-tooltip (window object position)
  (save-excursion
    (goto-char position)
    (let (beg end imgfile img s)
      (while (not (looking-at image-tooltip-re))
        (forward-char -1))
      (setq imgfile (match-string-no-properties 1))
      (if (file-exists-p imgfile)
      (progn
        (setq img (create-image (expand-file-name imgfile)
                    'imagemagick nil :width 800))
        (message (propertize "Look in the minibuffer"
                 'display img)))
    "No file found"))))

(defun img-match (limit)
  "Match bar in at the end of a word."
  (when (re-search-forward image-tooltip-re limit t)
    (flyspell-delete-region-overlays (match-beginning 1)
                     (match-end 1))
    t))

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '((img-match 1 '(face font-lock-keyword-face
                   help-echo image-tooltip))))))
Bounty Ended with 50 reputation awarded by student
Source Link
John Kitchin
  • 12.1k
  • 1
  • 23
  • 45

You probably want something like this. I think you need a function that matches the img, so you can get the region and remove flyspell overlays. Also you need to modify the add-hook call a bit.

(setq x-gtk-use-system-tooltips nil)

(defvar image-tooltip-re (concat  "\\\\includegraphics{\\(?1:.*\\."
                  (regexp-opt '("png" "PNG" "JPG" "jpeg"
                        "jpg" "JPEG" "eps" "EPS" "pdf"))
                  "\\)}")
  "Regexp to match included images")


(defun image-tooltip (window object position)
  (save-excursion
    (goto-char position)
    (let (beg end imgfile img s)
      (while (not (looking-at image-tooltip-re))
        (forward-char -1))
      (setq imgfile (match-string-no-properties 1))
      (if (file-exists-p imgfile)
      (progn
        (setq img (create-image (expand-file-name imgfile)
                    'imagemagick nil :width 800))
        (propertize "Look in the minibuffer"
            'display img))
    "No file found"))))

(defun img-match (limit)
  "Match bar in at the end of a word."
  (when (re-search-forward image-tooltip-re limit t)
    (flyspell-delete-region-overlays (match-beginning 1)
                     (match-end 1))
    t))

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '((img-match 1 '(face font-lock-keyword-face
                   help-echo image-tooltip))))))