commit 8641b79f8abc7e71fd33e633c47121c8cf7958e0
parent 30ab52ee079fe405ed3178a1f01561499945e247
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date: Sat, 5 Mar 2016 22:01:27 +0530
Introduce `emojify-program-contexts` as a replacement for emojify-prog-contexts
Diffstat:
3 files changed, 32 insertions(+), 35 deletions(-)
diff --git a/emojify.el b/emojify.el
@@ -369,20 +369,18 @@ These can have one of the following values
(define-obsolete-variable-alias 'emojify-emoji-style 'emojify-emoji-styles "0.2")
(define-obsolete-function-alias 'emojify-set-emoji-style 'emojify-set-emoji-styles "0.2")
-(defcustom emojify-prog-contexts
- 'both
+(defcustom emojify-program-contexts
+ '(comments string code)
"Contexts where emojis can be displayed in programming modes.
Possible values are
-`comments' - Display emojis only in comments
-`string' - Display emojis only in strings
-`both' - Display emojis in comments and strings
-`none' - Do not display emojis in programming modes"
- :type '(radio :tag "Contexts where emojis should be displayed in programming modes"
- (const :tag "Only in comments" comments)
- (const :tag "Only in string" string)
- (const :tag "Both in comments and string" both)
- (const :tag "Do not display emojis in programming modes" none))
+`comments' - Display emojis in comments
+`string' - Display emojis in strings
+`code' - Display emojis in code (this is applicable only for unicode emojis)"
+ :type '(set :tag "Contexts where emojis should be displayed in programming modes"
+ (const :tag "Display emojis in comments" comments)
+ (const :tag "Display emojis in string" string)
+ (const :tag "Display emojis in code" code))
:group 'emojify)
(defcustom emojify-inhibit-functions
@@ -417,20 +415,19 @@ The arguments IGNORED are, well ignored"
(and (eq major-mode 'org-mode)
(org-at-item-p)))
-(defun emojify-valid-prog-context-p (beg end)
- "Determine if the text between BEG and END should be used to display emojis.
-
-This returns non-nil if the region is valid according to `emojify-prog-contexts'"
- (when (and emojify-prog-contexts
- (memq emojify-prog-contexts '(string comments both)))
- (let ((syntax-beg (syntax-ppss beg))
- (syntax-end (syntax-ppss end))
- (pos (pcase emojify-prog-contexts
- (`string 3)
- (`comments 4)
- (`both 8))))
- (and (nth pos syntax-beg)
- (nth pos syntax-end)))))
+(defun emojify-valid-program-context-p (beg end)
+ "Determine if emoji should be displayed for text between BEG and END.
+
+This returns non-nil if the region is valid according to `emojify-program-contexts'"
+ (when emojify-program-contexts
+ (let* ((syntax-beg (syntax-ppss beg))
+ (syntax-end (syntax-ppss end))
+ (context (cond ((and (nth 3 syntax-beg)
+ (nth 3 syntax-end)) 'string)
+ ((and (nth 4 syntax-beg)
+ (nth 4 syntax-end)) 'comments)
+ (t 'code))))
+ (memql context emojify-program-contexts))))
(defun emojify-inside-org-src-p (point)
"Return non-nil if POINT is inside `org-mode' src block.
@@ -463,7 +460,7 @@ the visible area."
(nth 8 syntax-end)))))))))
(defun emojify-valid-ascii-emoji-context-p (beg end)
- "Determine if the okay to display for text between BEG and END."
+ "Determine if the okay to display ascii emoji between BEG and END."
;; The text is at the start of the buffer
(and (or (not (char-before beg))
;; 32 space since ? (? followed by a space) is not readable
@@ -781,8 +778,8 @@ TODO: Skip emojifying if region is already emojified."
emojify-emoji-styles)
;; Display unconditionally in non-prog mode
(or (not (derived-mode-p 'prog-mode 'tuareg--prog-mode))
- ;; In prog mode enable respecting `emojify-prog-contexts'
- (emojify-valid-prog-context-p match-beginning match-end))
+ ;; In prog mode enable respecting `emojify-program-contexts'
+ (emojify-valid-program-context-p match-beginning match-end))
;; Display ascii emojis conservatively, since they have potential
;; to be annoying consider d: in head:
diff --git a/test/emojify-test.el b/test/emojify-test.el
@@ -141,7 +141,7 @@
(emojify-tests-should-not-be-emojified unicode-emoji-pos)
(emojify-tests-should-not-be-emojified github-emoji-pos))))
-(ert-deftest emojify-tests-prog-contexts ()
+(ert-deftest emojify-tests-program-contexts ()
:tags '(core prog contextual)
(emojify-tests-with-emojified-static-buffer ";; :) :smile:\n\":smile:\"\n8)"
(let* ((comment-ascii-emoji-pos (+ 3 (point-min)))
@@ -149,28 +149,28 @@
(string-github-emoji-pos (1+ (line-beginning-position 2)))
(prog-ascii-emoji-pos (1+ (line-beginning-position 3))))
(emacs-lisp-mode)
- (setq emojify-prog-contexts 'both)
+ (setq emojify-program-contexts '(comments string))
(emojify-redisplay-emojis-in-region)
(emojify-tests-should-be-emojified comment-ascii-emoji-pos)
(emojify-tests-should-be-emojified comment-github-emoji-pos)
(emojify-tests-should-be-emojified string-github-emoji-pos)
(emojify-tests-should-not-be-emojified prog-ascii-emoji-pos)
- (setq emojify-prog-contexts 'comments)
+ (setq emojify-program-contexts '(comments))
(emojify-redisplay-emojis-in-region)
(emojify-tests-should-be-emojified comment-ascii-emoji-pos)
(emojify-tests-should-be-emojified comment-github-emoji-pos)
(emojify-tests-should-not-be-emojified string-github-emoji-pos)
(emojify-tests-should-not-be-emojified prog-ascii-emoji-pos)
- (setq emojify-prog-contexts 'string)
+ (setq emojify-program-contexts '(string))
(emojify-redisplay-emojis-in-region)
(emojify-tests-should-not-be-emojified comment-ascii-emoji-pos)
(emojify-tests-should-not-be-emojified comment-github-emoji-pos)
(emojify-tests-should-be-emojified string-github-emoji-pos)
(emojify-tests-should-not-be-emojified prog-ascii-emoji-pos)
- (setq emojify-prog-contexts 'none)
+ (setq emojify-program-contexts '())
(emojify-redisplay-emojis-in-region)
(emojify-tests-should-not-be-emojified comment-ascii-emoji-pos)
(emojify-tests-should-not-be-emojified comment-github-emoji-pos)
diff --git a/test/test-helper.el b/test/test-helper.el
@@ -37,7 +37,7 @@ Helps isolate tests from each other's customizations."
(emojify-saved-inhibit-major-modes emojify-inhibit-major-modes)
(emojify-saved-inhibit-in-buffer-functions emojify-inhibit-in-buffer-functions)
(emojify-saved-emoji-style emojify-emoji-styles)
- (emojify-saved-prog-contexts emojify-prog-contexts)
+ (emojify-saved-program-contexts emojify-program-contexts)
(emojify-saved-inhibit-functions emojify-inhibit-functions)
(emojify-saved-point-entered-behaviour emojify-point-entered-behaviour)
(emojify-saved-show-help emojify-show-help)
@@ -53,7 +53,7 @@ Helps isolate tests from each other's customizations."
emojify-display-style emojify-saved-display-style
emojify-inhibit-major-modes emojify-saved-inhibit-major-modes
emojify-inhibit-in-buffer-functions emojify-saved-inhibit-in-buffer-functions
- emojify-prog-contexts emojify-saved-prog-contexts
+ emojify-program-contexts emojify-saved-program-contexts
emojify-inhibit-functions emojify-saved-inhibit-functions
emojify-point-entered-behaviour emojify-saved-point-entered-behaviour
emojify-show-help emojify-saved-show-help