Created
October 1, 2018 05:11
-
-
Save chuntaro/b403e7d0f6d7c459136099759c281b6a to your computer and use it in GitHub Desktop.
Emacs でポイントの下の画像ファイル名をツールチップに表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; -*- lexical-binding: t; -*- | |
| (defun image-tooltip-at-point () | |
| "ポイントやマウスカーソルの下の画像ファイルをツールチップ内に表示します。 | |
| 使い方: | |
| (define-key c-mode-map \"\\C-co\" 'image-tooltip-at-point) | |
| (define-key c-mode-map [mouse-1] 'image-tooltip-at-point) | |
| ./very-sorry.png | |
| ./very-sorry.gif | |
| 上記のようなファイル名を`ffap'が認識出来れば C-c o やマウス左クリックでポップアップします。" | |
| (interactive) | |
| (unless (display-graphic-p) | |
| (error "Window system required.")) | |
| (require 'ffap) | |
| (let ((file (ffap-file-at-point))) | |
| (when file | |
| (unless (and (stringp file) | |
| (not (directory-name-p file)) | |
| (file-exists-p (setq file (expand-file-name file)))) | |
| (error "File not found.")) | |
| (when (image-type-from-file-name file) | |
| (let* ((x-y (window-absolute-pixel-position)) | |
| (tooltip-frame-parameters `((left . ,(+ (car x-y) tooltip-x-offset)) | |
| (top . ,(+ (cdr x-y) tooltip-y-offset)) | |
| (internal-border-width . 0) | |
| (border-width . 0))) | |
| (image (create-image file)) | |
| (x-gtk-use-system-tooltips nil)) ; Linux ではこれしないと表示されない… | |
| (image-animate image) | |
| (tooltip-show (propertize "a" 'display image))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment