summaryrefslogtreecommitdiff
path: root/helm-lib.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2016-05-21 08:20:42 +0200
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2016-05-21 08:20:42 +0200
commit43777d560b1f1cbf7fadadc2459d9e34cb1acee2 (patch)
tree0aaf471a6604ecf003ea7660b04ef5aa74903069 /helm-lib.el
parent033fa11c38a52d40e80c7e7870e0b4965f164711 (diff)
Allow reusing the dabbrev assoc buffers fn in other places.
* helm-dabbrev.el (helm-dabbrev--same-major-mode-p): Now reuse helm-same-major-mode-p. * helm-lib.el (helm-same-major-mode-p): Moved here from helm-dabbrev--same-major-mode-p. Now check also if initial buffer is derived from current-buffer.
Diffstat (limited to 'helm-lib.el')
-rw-r--r--helm-lib.el39
1 files changed, 39 insertions, 0 deletions
diff --git a/helm-lib.el b/helm-lib.el
index d61fcc0d..cbea49f4 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -488,6 +488,45 @@ Add spaces at end if needed to reach WIDTH when STR is shorter than WIDTH."
"CANDIDATE is symbol or string.
See `kill-new' for argument REPLACE."
(kill-new (helm-stringify candidate) replace))
+
+
+;;; Modes
+;;
+(defun helm-same-major-mode-p (start-buffer alist)
+ ;; START-BUFFER is the current-buffer where we start searching.
+ ;; Determine the major-mode of START-BUFFER as `cur-maj-mode'.
+ ;; Each time the loop go in another buffer we try to find if its
+ ;; `major-mode' is:
+ ;; - same as the `cur-maj-mode'
+ ;; - derived from `cur-maj-mode'
+ ;; - have an assoc entry (major-mode . cur-maj-mode)
+ ;; - have an rassoc entry (cur-maj-mode . major-mode)
+ ;; - check if one of these entries inherit from another one in
+ ;; `alist'.
+ (let* ((cur-maj-mode (with-current-buffer start-buffer major-mode))
+ (maj-mode major-mode)
+ (c-assoc-mode (assq cur-maj-mode alist))
+ (c-rassoc-mode (rassq cur-maj-mode alist))
+ (o-assoc-mode (assq major-mode alist))
+ (o-rassoc-mode (rassq major-mode alist))
+ (cdr-c-assoc-mode (cdr c-assoc-mode))
+ (cdr-o-assoc-mode (cdr o-assoc-mode)))
+ (or (eq major-mode cur-maj-mode)
+ (derived-mode-p cur-maj-mode)
+ (with-current-buffer start-buffer
+ (derived-mode-p maj-mode))
+ (or (eq cdr-c-assoc-mode major-mode)
+ (eq (car c-rassoc-mode) major-mode)
+ (eq (cdr (assq cdr-c-assoc-mode alist))
+ major-mode)
+ (eq (car (rassq cdr-c-assoc-mode alist))
+ major-mode))
+ (or (eq cdr-o-assoc-mode cur-maj-mode)
+ (eq (car o-rassoc-mode) cur-maj-mode)
+ (eq (cdr (assq cdr-o-assoc-mode alist))
+ cur-maj-mode)
+ (eq (car (rassq cdr-o-assoc-mode alist))
+ cur-maj-mode)))))
;;; Files routines
;;