From 8c923bbbd61b228f485b9204a6a98eee33f7e16f Mon Sep 17 00:00:00 2001 From: bmag Date: Thu, 9 Aug 2018 11:38:27 +0300 Subject: [PATCH] Add back support for Emacs 24.4 and 24.5 - re-add purpose-alist-get - fix Package-Requires - re-add name argument for purpose-conf objects (turns out it is still mandatory in 24.5, only made obsolete in 25.1) --- .gitignore | 1 + window-purpose-configuration.el | 3 ++- window-purpose-fixes.el | 7 +++++-- window-purpose-switch.el | 2 +- window-purpose-utils.el | 11 +++++++++++ window-purpose-x.el | 11 ++++++++--- window-purpose.el | 2 +- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index cc05f55..3aa557a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist # Ecukes /features/project/.cask /features/project/test/*.el +/test/user-input.txt diff --git a/window-purpose-configuration.el b/window-purpose-configuration.el index 82bb964..e341944 100644 --- a/window-purpose-configuration.el +++ b/window-purpose-configuration.el @@ -373,7 +373,8 @@ configuration. Example: (purpose-set-extension-configuration :python - (purpose-conf :mode-purposes + (purpose-conf \"py\" + :mode-purposes '((python-mode . python) (inferior-python-mode . interpreter)))) diff --git a/window-purpose-fixes.el b/window-purpose-fixes.el index 9ab105a..31d3ac6 100644 --- a/window-purpose-fixes.el +++ b/window-purpose-fixes.el @@ -61,7 +61,8 @@ This function should be advised around ;;; Helm's buffers should be ignored, and they should have their own purpose (defvar purpose--helm-conf - (purpose-conf :regexp-purposes '(("^\\*Helm" . helm) + (purpose-conf "helm" + :regexp-purposes '(("^\\*Helm" . helm) ("^\\*helm" . helm))) "Purpose configuration for helm.") (defun purpose--fix-helm () @@ -130,7 +131,7 @@ When `purpose--active-p' is nil, call original `neo-global--create-window'." ;; `purpose--special-action-sequence' will try to call it) (purpose-set-extension-configuration :neotree - (purpose-conf :name-purposes `((,neo-buffer-name . Neotree)))) + (purpose-conf "Neotree" :name-purposes `((,neo-buffer-name . Neotree)))) (add-to-list 'purpose-special-action-sequences '(Neotree purpose-display-reuse-window-buffer purpose-display-reuse-window-purpose @@ -198,6 +199,7 @@ Don't call this function before `popwin' is loaded." '(purpose-set-extension-configuration :guide-key (purpose-conf + "guide-key" :name-purposes `((,guide-key/guide-buffer-name . guide-key)))))) @@ -212,6 +214,7 @@ Don't call this function before `popwin' is loaded." (purpose-set-extension-configuration :which-key (purpose-conf + "which-key" :name-purposes `((,which-key-buffer-name . which-key))))))) diff --git a/window-purpose-switch.el b/window-purpose-switch.el index 30166c6..61310f8 100644 --- a/window-purpose-switch.el +++ b/window-purpose-switch.el @@ -775,7 +775,7 @@ If ALIST is nil, it is ignored and `purpose--alist' is used instead." (let* ((user-action-sequence .user-action-sequence) (special-action-sequence (purpose--special-action-sequence buffer alist)) - (normal-action-sequence (alist-get + (normal-action-sequence (purpose-alist-get (or .action-order purpose-default-action-order) purpose-action-sequences)) diff --git a/window-purpose-utils.el b/window-purpose-utils.el index 55d19df..7bcb6b0 100644 --- a/window-purpose-utils.el +++ b/window-purpose-utils.el @@ -43,6 +43,17 @@ return the formatted string. FORMAT-STRING and ARGS are passed to (apply #'message format-string args) (apply #'format format-string args))) +;; define our (limited) version of alist-get +(defun purpose-alist-get (key alist &optional default _remove) + "Get KEY's value in ALIST. +If no such key, return DEFAULT. +When setting KEY's value, if the new value is equal to DEFAULT and +REMOVE is non-nil, then delete the KEY instead." + (let ((entry (assq key alist))) + (if entry + (cdr entry) + default))) + (defun purpose-alist-set (key value alist) "Set VALUE to be the value associated to KEY in ALIST. This doesn't change the original alist, but returns a modified copy." diff --git a/window-purpose-x.el b/window-purpose-x.el index 4a1b6f1..ae51864 100644 --- a/window-purpose-x.el +++ b/window-purpose-x.el @@ -68,9 +68,11 @@ Has a main 'edit window, and two side windows - 'dired and 'buffers. All windows are purpose-dedicated.") -;; the name arg ("purpose-x-code1") is necessary for Emacs 24.3 and older +;; the name arg ("purpose-x-code1") is necessary for Emacs 24.5 and older +;; (omitting it produces an "Invalid slot name" error) (defvar purpose-x-code1-purpose-config - (purpose-conf :mode-purposes + (purpose-conf "purpose-x-code1" + :mode-purposes '((ibuffer-mode . buffers) (dired-mode . dired) (imenu-list-major-mode . ilist)))) @@ -189,11 +191,13 @@ imenu." ;;; - `purpose-x-magit-off' (defvar purpose-x-magit-single-conf - (purpose-conf :regexp-purposes '(("^\\*magit" . magit))) + (purpose-conf "magit-single" + :regexp-purposes '(("^\\*magit" . magit))) "Configuration that gives each magit major mode the same purpose.") (defvar purpose-x-magit-multi-conf (purpose-conf + "magit-multi" :mode-purposes '((magit-diff-mode . magit-diff) (magit-status-mode . magit-status) (magit-log-mode . magit-log) @@ -381,6 +385,7 @@ The configuration is updated according to (interactive) (cl-flet ((joiner (x) (cons x 'popup))) (let ((conf (purpose-conf + "popwin" :mode-purposes (mapcar #'joiner purpose-x-popwin-major-modes) :name-purposes (mapcar #'joiner purpose-x-popwin-buffer-names) :regexp-purposes (mapcar #'joiner diff --git a/window-purpose.el b/window-purpose.el index 4ccad3b..87c7375 100644 --- a/window-purpose.el +++ b/window-purpose.el @@ -7,7 +7,7 @@ ;; Version: 1.6.1 ;; Keywords: frames ;; Homepage: https://github.com/bmag/emacs-purpose -;; Package-Requires: ((emacs "25") (imenu-list "0.1")) +;; Package-Requires: ((emacs "24.4") (let-alist "1.0.3") (imenu-list "0.1")) ;; This file is not part of GNU Emacs.