emacs-emojify

fork of https://github.com/iqbalansari/emacs-emojify
Log | Files | Refs | LICENSE

commit 5005e6a2c39725cf08c7f9583a6d6cbd40fd2a3c
parent 4618e37dc7266421c8892047d0635dddd21d4107
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date:   Tue,  1 Dec 2015 23:27:52 +0530

Add `emojify-overlays-at`, compatibility wrapper around `overlays-at`

Hopefully restores compatibility with Emacs 24.3

Diffstat:
Memojify.el | 27++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/emojify.el b/emojify.el @@ -82,6 +82,31 @@ This provides a compatibility version for previous versions." (aref (font-info default-font) 3)) (t (frame-char-height)))))) +(defun emojify-overlays-at (pos &optional sorted) + "Return a list of the overlays that contain the character at POS. +If SORTED is non-nil, then sort them by decreasing priority. + +The SORTED argument was introduced in Emacs 24.4, along with the incompatible +change that overlay priorities can be any Lisp object (earlier they were +restricted to integer and nil). This version uses the SORTED argument of +`overlays-at' on Emacs version 24.4 onwards and manually sorts the overlays by +priority on lower versions." + (if (version< emacs-version "24.4") + (let ((overlays-at-pos (overlays-at pos))) + (if sorted + (seq-sort (lambda (overlay1 overlay2) + (if (and (overlay-get overlay2 'priority) + (overlay-get overlay1 'priority)) + ;; If both overlays have priorities compare them + (< (overlay-get overlay1 'priority) + (overlay-get overlay2 'priority)) + ;; Otherwise overlay with nil priority is sorted below + ;; the one with integer value otherwise preserve order + (not (overlay-get overlay1 'priority)))) + overlays-at-pos) + overlays-at-pos)) + (overlays-at pos sorted))) + ;; Utility functions @@ -621,7 +646,7 @@ and end of region respectively." (let* ((overlays-with-face (seq-filter (lambda (overlay) (and (overlay-get overlay 'face) (face-background (overlay-get overlay 'face) nil 'default))) - (overlays-at beg t)))) + (emojify-overlays-at beg t)))) (when overlays-with-face (face-background (overlay-get (car (last overlays-with-face)) 'face) nil 'default))))