Skip to content

Commit

Permalink
Fix #85 #86 Remove support for Emacs 24
Browse files Browse the repository at this point in the history
* autoload `purpose-conf'
* remove purpose-conf instance names
* remove `subr-x' shims
* remove `purpose-alist-get'
* remove old style advice shims
* bump emacs version package requirement
  • Loading branch information
wyuenho authored and bmag committed Aug 9, 2018
1 parent 64caa53 commit a60c0ef
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 408 deletions.
8 changes: 2 additions & 6 deletions window-purpose-configuration.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@

;;; Types

;; `purpose-conf' is not an autoload because there is a bug in autoloading
;; `defclass' in Emacs 24.3. (no problem with Emacs 24.4)
;; If we decide to drop support for Emacs 24.3, we can make `purpose-conf' an
;; autoload again.
;;;###autoload
(defclass purpose-conf ()
((mode-purposes :initarg :mode-purposes
:initform '()
Expand Down Expand Up @@ -376,8 +373,7 @@ configuration.
Example:
(purpose-set-extension-configuration
:python
(purpose-conf \"py\"
:mode-purposes
(purpose-conf :mode-purposes
'((python-mode . python)
(inferior-python-mode . interpreter))))
Expand Down
3 changes: 2 additions & 1 deletion window-purpose-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
;;; Code:

(require 'window-purpose-configuration)
(eval-when-compile (require 'subr-x))

(defgroup purpose nil
"purpose-mode configuration"
Expand Down Expand Up @@ -190,7 +191,7 @@ FRAME defaults to the selected frame."
(delete-dups
(append (list default-purpose)
(purpose-flatten
(mapcar #'purpose-hash-table-values
(mapcar #'hash-table-values
(append (when purpose-use-default-configuration
(list purpose--default-name-purposes
purpose--default-mode-purposes
Expand Down
158 changes: 52 additions & 106 deletions window-purpose-fixes.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,19 @@
;;; when Purpose is on. Solution: make the buffer's window dedicated while
;;; executing `compilation-next-error-function'

(define-purpose-compatible-advice 'compilation-next-error-function
:around purpose--fix-compilation-next-error
(&rest args)
"Integrate Purpose and `compilation-next-error-function'.
(defun purpose--fix-compilation-next-error (oldfun &rest args)
"Integrate Purpose and `compilation-next-error-function'.
Advice that prevents `compilation-next-error-function' from hiding the
compilation buffer. This is done by ensuring that the buffer is
dedicated for the duration of the function.
This function should be advised around
`compilation-next-error-function'."
;; new style advice
((let* ((compilation-window (get-buffer-window (marker-buffer (point-marker))))
(old-window-dedicated-p (window-dedicated-p compilation-window)))
(set-window-dedicated-p compilation-window t)
(unwind-protect
(apply oldfun args)
(set-window-dedicated-p compilation-window old-window-dedicated-p))))

;; old style advice
((let* ((compilation-window (get-buffer-window (marker-buffer (point-marker))))
(old-window-dedicated-p (window-dedicated-p compilation-window)))
(set-window-dedicated-p compilation-window t)
(unwind-protect
ad-do-it
(set-window-dedicated-p compilation-window old-window-dedicated-p)))))
(let* ((compilation-window (get-buffer-window (marker-buffer (point-marker))))
(old-window-dedicated-p (window-dedicated-p compilation-window)))
(set-window-dedicated-p compilation-window t)
(unwind-protect
(apply oldfun args)
(set-window-dedicated-p compilation-window old-window-dedicated-p))))



Expand All @@ -72,8 +61,7 @@ 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 "helm"
:regexp-purposes '(("^\\*Helm" . helm)
(purpose-conf :regexp-purposes '(("^\\*Helm" . helm)
("^\\*helm" . helm)))
"Purpose configuration for helm.")
(defun purpose--fix-helm ()
Expand Down Expand Up @@ -124,47 +112,33 @@ Override the display and creation of the neotree window.
When opening files from the neotree window, use Purpose only when
necessary.
Note: Don't call this function before `neotree' is loaded."
(define-purpose-compatible-advice 'neo-global--create-window
:around purpose-fix-neotree-create-window-advice
(&rest args)
"Override `neo-global--create-window' with `purpose--fix-create-neo-window'.
(defun purpose-fix-neotree-create-window-advice (oldfun &rest args)
"Override `neo-global--create-window' with `purpose--fix-create-neo-window'.
When `purpose--active-p' is nil, call original `neo-global--create-window'."
;; new style adivce
((if purpose--active-p
(purpose--fix-create-neo-window)
(apply oldfun args)))
;; old style advice
((if purpose--active-p
(setq ad-return-value (purpose--fix-create-neo-window))
ad-do-it)))

(define-purpose-compatible-advice 'neo-open-file
:around purpose-fix-neotree-open-file-advice
(full-path &optional arg)
"When ARG is nil, make sure Purpose is off while executing `neo-open-file'."
;; new style advice
((if (and purpose--active-p (null arg))
(find-file full-path)
(without-purpose (funcall oldfun full-path arg))))
;; old style advice
((if (and purpose--active-p (null arg))
(setq ad-return-value (find-file full-path))
(without-purpose ad-do-it))))
(if purpose--active-p
(purpose--fix-create-neo-window)
(apply oldfun args)))

(defun purpose-fix-neotree-open-file-advice (oldfun full-path &optional arg)
"When ARG is nil, make sure Purpose is off while executing `neo-open-file'."
(if (and purpose--active-p (null arg))
(find-file full-path)
(without-purpose (funcall oldfun full-path arg))))

;; using purpose 'Neotree, because using 'neotree causes problems with
;; `purpose-special-action-sequences' ('neotree is also a function, so
;; `purpose--special-action-sequence' will try to call it)
(purpose-set-extension-configuration
:neotree
(purpose-conf "Neotree" :name-purposes `((,neo-buffer-name . Neotree))))
(purpose-conf :name-purposes `((,neo-buffer-name . Neotree))))
(add-to-list 'purpose-special-action-sequences
'(Neotree purpose-display-reuse-window-buffer
purpose-display-reuse-window-purpose
purpose--fix-display-neotree))
(purpose-advice-add 'neo-global--create-window
:around 'purpose-fix-neotree-create-window-advice)
(purpose-advice-add 'neo-open-file
:around 'purpose-fix-neotree-open-file-advice))
(advice-add 'neo-global--create-window
:around 'purpose-fix-neotree-create-window-advice)
(advice-add 'neo-open-file
:around 'purpose-fix-neotree-open-file-advice))

(defun purpose--fix-neotree ()
"Call `purpose--fix-neotree-1' after `neotree' is loaded."
Expand All @@ -181,26 +155,16 @@ When `purpose--active-p' is nil, call original `neo-global--create-window'."
(defun purpose--fix-org-no-popups-1 ()
"Make Purpose inactive during some functions that use `org-no-popups'.
Don't call this function before `org' is loaded."
(define-purpose-compatible-advice 'org-switch-to-buffer-other-window
:around purpose--fix-org-switch-to-buffer-other-window
(&rest args)
"Make Purpose inactive during `org-switch-to-buffer-other-window'."
;; new style advice
((without-purpose (apply oldfun args)))
;; old style advice
((without-purpose ad-do-it)))
(define-purpose-compatible-advice 'org-get-location
:around purpose--fix-org-get-location
(&rest args)
"Make Purpose inactive during `org-get-location'."
;; new style advice
((without-purpose (apply oldfun args)))
;; old style advice
((without-purpose ad-do-it)))
(purpose-advice-add 'org-switch-to-buffer-other-window
:around 'purpose--fix-org-switch-to-buffer-other-window)
(purpose-advice-add 'org-get-location
:around 'purpose--fix-org-get-location))
(defun purpose--fix-org-switch-to-buffer-other-window (oldfun &rest args)
"Make Purpose inactive during `org-switch-to-buffer-other-window'."
(without-purpose (apply oldfun args)))
(defun purpose--fix-org-get-location (oldfun &rest args)
"Make Purpose inactive during `org-get-location'."
(without-purpose (apply oldfun args)))
(advice-add 'org-switch-to-buffer-other-window
:around 'purpose--fix-org-switch-to-buffer-other-window)
(advice-add 'org-get-location
:around 'purpose--fix-org-get-location))

(defun purpose--fix-org-no-popups ()
"Call `purpose--fix-org-no-popups-1' after `org' is loaded."
Expand All @@ -214,16 +178,11 @@ Don't call this function before `org' is loaded."
(defun purpose--fix-popwin-1 ()
"Make Purpose inactive during `popwin:replicate-window-config'.
Don't call this function before `popwin' is loaded."
(define-purpose-compatible-advice 'popwin:replicate-window-config
:around purpose--fix-popwin-replicate
(&rest args)
"Make Purpose inactive during `popwin:replicate-window-config'."
;; new style advice
((without-purpose (apply oldfun args)))
;; old style advice
((without-purpose ad-do-it)))
(purpose-advice-add 'popwin:replicate-window-config
:around 'purpose--fix-popwin-replicate))
(defun purpose--fix-popwin-replicate (oldfun &rest args)
"Make Purpose inactive during `popwin:replicate-window-config'."
(without-purpose (apply oldfun args)))
(advice-add 'popwin:replicate-window-config
:around 'purpose--fix-popwin-replicate))

(defun purpose--fix-popwin ()
"Call `purpose--fix-popwin-1' after `popwin' is loaded."
Expand All @@ -239,7 +198,6 @@ 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))))))


Expand All @@ -254,7 +212,6 @@ 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)))))))


Expand All @@ -264,27 +221,16 @@ Don't call this function before `popwin' is loaded."
"Let magit-popup display help windows the way it wants."
(eval-after-load 'magit-popup
'(progn
(define-purpose-compatible-advice 'magit-popup-describe-function
:around purpose--fix-magit-popup-help
(&rest args)
"Make Purpose inactive during `magit-popup-describe-function'."
;; new style advice
((without-purpose (apply oldfun args)))
;; old style advice
((without-purpose ad-do-it)))
(define-purpose-compatible-advice 'magit-popup-manpage
:around purpose--fix-magit-popup-help
(&rest args)
"Make Purpose inactive during `magit-popup-manpage'."
;; new style advice
((without-purpose (apply oldfun args)))
;; old style advice
((without-purpose ad-do-it)))
(purpose-advice-add 'magit-popup-describe-function
:around 'purpose--fix-magit-popup-help)
(purpose-advice-add 'magit-popup-manpage
:around 'purpose--fix-magit-popup-help)
)))
(defun purpose--fix-magit-popup-help (oldfun &rest args)
"Make Purpose inactive during `magit-popup-describe-function'."
(without-purpose (apply oldfun args)))
(defun purpose--fix-magit-popup-help (oldfun &rest args)
"Make Purpose inactive during `magit-popup-manpage'."
(without-purpose (apply oldfun args)))
(advice-add 'magit-popup-describe-function
:around 'purpose--fix-magit-popup-help)
(advice-add 'magit-popup-manpage
:around 'purpose--fix-magit-popup-help))))

;;; install fixes

Expand All @@ -303,8 +249,8 @@ are:
- 'which-key : don't integrate with which-key"
(interactive)
(unless (member 'compilation-next-error-function exclude)
(purpose-advice-add 'compilation-next-error-function
:around #'purpose--fix-compilation-next-error))
(advice-add 'compilation-next-error-function
:around #'purpose--fix-compilation-next-error))
(unless (member 'lv exclude)
(purpose--fix-hydra-lv))
(unless (member 'helm exclude)
Expand Down
5 changes: 3 additions & 2 deletions window-purpose-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
(require 'cl-lib)
(require 'ring)
(require 'window-purpose-core)
(eval-when-compile (require 'subr-x))

(defconst purpose--built-in-layouts-dir
(when load-file-name
Expand Down Expand Up @@ -233,8 +234,8 @@ WINDOW must be a live window and defaults to the selected one."
"Get a list of all filenames that end in SUFFIX in DIRECTORY.
The base filenames without the suffix are returned."
(cl-loop for filename in (directory-files directory nil nil t)
if (purpose--suffix-p suffix filename)
collect (purpose--remove-suffix suffix filename)))
if (string-suffix-p suffix filename)
collect (string-remove-suffix suffix filename)))

(defun purpose--file-with-suffix (name suffix directory)
"Get file with basename NAME and suffix SUFFIX in DIRECTORY.
Expand Down

0 comments on commit a60c0ef

Please sign in to comment.