Install helm-descbinds and helm-describe-modes

This commit is contained in:
Gergely Polonkai 2016-10-20 15:50:01 +02:00
parent 68b8ff7878
commit 4bd823d7af
7 changed files with 579 additions and 0 deletions

View File

@ -0,0 +1,65 @@
;;; helm-descbinds-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "helm-descbinds" "helm-descbinds.el" (22536
;;;;;; 51973 686162 683000))
;;; Generated autoloads from helm-descbinds.el
(defvar helm-descbinds-mode nil "\
Non-nil if Helm-Descbinds mode is enabled.
See the `helm-descbinds-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `helm-descbinds-mode'.")
(custom-autoload 'helm-descbinds-mode "helm-descbinds" nil)
(autoload 'helm-descbinds-mode "helm-descbinds" "\
Use `helm' for `describe-bindings'.
\(fn &optional ARG)" t nil)
(autoload 'helm-descbinds-install "helm-descbinds" "\
Use `helm-descbinds' as a replacement of `describe-bindings'.
\(fn)" t nil)
(autoload 'helm-descbinds-uninstall "helm-descbinds" "\
Restore original `describe-bindings'.
\(fn)" t nil)
(autoload 'helm-descbinds "helm-descbinds" "\
A convenient helm version of `describe-bindings'.
Turning on `helm-descbinds-mode' is the recommended way to
install this command to replace `describe-bindings'.
You complete against a list of keys + command pairs presented in
a similar way as `describe-bindings' does, split into sections
defined by the types of the key bindings (minor and major modes,
global bindings, etc).
The default action executes a command as if the binding had been
entered, or narrows the commands according to a prefix key,
respectively.
The persistent action pops up a help buffer for the selected
command without quitting.
For key translation maps, the default actions are not very
useful, yet they are listed for completeness.
\(fn &optional PREFIX BUFFER)" t nil)
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; helm-descbinds-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; -*- no-byte-compile: t -*-
(define-package "helm-descbinds" "20160916.713" "A convenient `describe-bindings' with `helm'" '((helm "1.5")) :url "https://github.com/emacs-helm/helm-descbinds" :keywords '("helm" "help"))

View File

@ -0,0 +1,293 @@
;;; helm-descbinds.el --- A convenient `describe-bindings' with `helm' -*- lexical-binding: t -*-
;; Copyright (C) 2008, 2009, 2010 Taiki SUGAWARA <buzz.taiki@gmail.com>
;; Copyright (C) 2012, 2013 Michael Markert <markert.michael@googlemail.com>
;; Copyright (C) 2013 Daniel Hackney <dan@haxney.org>
;; Copyright (C) 2015, 2016 Michael Heerdegen <michael_heerdegen@web.de>
;; Author: Taiki SUGAWARA <buzz.taiki@gmail.com>
;; URL: https://github.com/emacs-helm/helm-descbinds
;; Package-Version: 20160916.713
;; Keywords: helm, help
;; Version: 1.12
;; Package-Requires: ((helm "1.5"))
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; This package is a replacement of `describe-bindings' for Helm.
;; Usage:
;;
;; You can use this package independently from Helm - in particular,
;; you don't need to turn on `helm-mode' to be able to use this. Helm
;; just needs to be installed.
;;
;; Add followings on your .emacs.
;;
;; (require 'helm-descbinds)
;; (helm-descbinds-mode)
;;
;; or use customize to set `helm-descbinds-mode' to t.
;;
;; Now, `describe-bindings' is replaced with `helm-descbinds'. As
;; usual, type `C-h b', or any incomplete key sequence plus C-h , to
;; run `helm-descbinds'. The bindings are presented in a similar way
;; as `describe-bindings ' does, but you can use completion to find
;; the command you searched for and execute it, or view it's
;; documentation.
;;
;; In the Helm completions buffer, you match key bindings with the
;; Helm interface:
;;
;; - When you type RET, the selected candidate command is executed.
;;
;; - When you hit RET on a prefix key, the candidates are narrowed to
;; this prefix
;;
;; - When you type TAB, you can select "Execute", "Describe" or "Find
;; Function" by the menu (i.e. these are the available "actions"
;; and are of course also available via their usual shortcuts).
;;
;; - When you type C-z (aka "persistent action"), the selected
;; command is described without quitting Helm.
;;; Code:
(eval-when-compile (require 'cl-lib)) ;cl-loop
(require 'helm)
(defgroup helm-descbinds nil
"A convenient `describe-bindings' with `helm'."
:prefix "helm-descbinds-"
:group 'helm)
(defcustom helm-descbinds-actions
'(("Execute" . helm-descbinds-action:execute)
("Describe" . helm-descbinds-action:describe)
("Find Function" . helm-descbinds-action:find-func))
"Actions of selected candidate."
:type '(repeat
(cons
:tag "Action"
(string :tag "Name")
(function :tag "Function"))))
(defcustom helm-descbinds-candidate-formatter
#'helm-descbinds-default-candidate-formatter
"Candidate formatter function.
This function will be called with two arguments KEY and BINDING."
:type 'function)
(defcustom helm-descbinds-window-style 'one-window
"Window splitting style."
:type '(choice
(const :tag "One Window" one-window)
(const :tag "Same Window" same-window)
(const :tag "Split Window" split-window)))
(defcustom helm-descbinds-section-order
'("Major Mode Bindings" "Minor Mode Bindings" "Global Bindings")
"A list of section order by name regexp."
:type '(repeat (regexp :tag "Regexp")))
(defvar helm-descbinds-Orig-describe-bindings (symbol-function 'describe-bindings))
(defvar helm-descbind--initial-full-frame helm-full-frame)
;;;###autoload
(define-minor-mode helm-descbinds-mode
"Use `helm' for `describe-bindings'."
:group 'helm-descbinds
:global t
(if helm-descbinds-mode
(advice-add 'describe-bindings :override #'helm-descbinds)
(advice-remove 'describe-bindings #'helm-descbinds)))
;;;###autoload
(defun helm-descbinds-install ()
"Use `helm-descbinds' as a replacement of `describe-bindings'."
(interactive)
(helm-descbinds-mode 1))
(make-obsolete 'helm-descbinds-install 'helm-descbinds-mode "1.08")
;;;###autoload
(defun helm-descbinds-uninstall ()
"Restore original `describe-bindings'."
(interactive)
(helm-descbinds-mode -1))
(make-obsolete 'helm-descbinds-uninstall 'helm-descbinds-mode "1.08")
(defun helm-descbinds-all-sections (buffer &optional prefix menus)
(with-temp-buffer
(let ((indent-tabs-mode t))
(describe-buffer-bindings buffer prefix menus))
(goto-char (point-min))
(let ((header-p (not (= (char-after) ?\f)))
sections header section)
(while (not (eobp))
(cond
(header-p
(setq header (buffer-substring-no-properties
(point)
(line-end-position)))
(setq header-p nil)
(forward-line 3))
((= (char-after) ?\f)
(push (cons header (nreverse section)) sections)
(setq section nil)
(setq header-p t))
((looking-at "^[ \t]*$")
;; ignore
)
(t
(let ((binding-start (save-excursion
(and (re-search-forward "\t+" nil t)
(match-end 0))))
key binding)
(when binding-start
(setq key (buffer-substring-no-properties (point) binding-start)
key (replace-regexp-in-string"^[ \t\n]+" "" key)
key (replace-regexp-in-string"[ \t\n]+$" "" key))
(goto-char binding-start)
(setq binding (buffer-substring-no-properties
binding-start
(line-end-position)))
(unless (member binding '("self-insert-command"))
(push (cons key binding) section))))))
(forward-line))
(push (cons header (nreverse section)) sections)
(nreverse sections))))
(defun helm-descbinds-action:execute (candidate)
"An action that execute selected CANDIDATE command."
(let ((x (cdr candidate))
(helm-full-frame helm-descbind--initial-full-frame))
(cond
((equal x "Keyboard Macro")
(command-execute (kbd (car candidate))))
((stringp x)
(insert x))
((commandp x)
(run-at-time 0.01 nil (lambda (command) (call-interactively command)) x)))))
(defun helm-descbinds-action:describe (candidate)
"An action that describe selected CANDIDATE function."
(let ((name (cdr candidate)))
(if (equal name "Keyboard Macro")
(describe-key (kbd (car candidate)))
(describe-function name))))
(defun helm-descbinds-action:find-func (candidate)
"An action that find selected CANDIDATE function."
(find-function (cdr candidate)))
(defun helm-descbinds-default-candidate-formatter (key binding)
"Default candidate formatter."
(format "%-10s\t%s" key binding))
(defun helm-descbinds-order-section (section)
(cl-loop for n = 0 then (1+ n)
for regexp in helm-descbinds-section-order
if (and (car section) (string-match regexp (car section)))
return n
finally
return n))
(defun helm-descbinds-transform-candidates (candidates)
(cl-loop for (key . command) in candidates
for sym = (intern-soft command)
collect
(cons (funcall helm-descbinds-candidate-formatter key command)
(cons key (if (commandp sym) sym command)))))
(defun helm-descbinds-action-transformer (actions cand)
"Default action transformer for `helm-descbinds'.
Provide a useful behavior for prefix commands."
(if (stringp (cdr cand))
(helm-make-actions
"helm-descbinds this prefix"
(lambda (cand)
(describe-bindings (kbd (car cand)))))
actions))
(defun helm-descbinds-sources (buffer &optional prefix menus)
(mapcar
(lambda (section)
(helm-descbinds-source (car section) (cdr section)))
(sort
(helm-descbinds-all-sections buffer prefix menus)
(lambda (a b)
(< (helm-descbinds-order-section a)
(helm-descbinds-order-section b))))))
(defclass helm-descbinds-source-class (helm-source-sync) ())
(defun helm-descbinds-source (name candidates)
(when (and name candidates)
(helm-make-source name 'helm-descbinds-source-class
:candidates candidates
:candidate-transformer #'helm-descbinds-transform-candidates
:filtered-candidate-transformer #'helm-fuzzy-highlight-matches
:persistent-action #'helm-descbinds-action:describe
:action-transformer #'helm-descbinds-action-transformer
:action 'helm-descbinds-actions)))
;;;###autoload
(defun helm-descbinds (&optional prefix buffer)
"A convenient helm version of `describe-bindings'.
Turning on `helm-descbinds-mode' is the recommended way to
install this command to replace `describe-bindings'.
You complete against a list of keys + command pairs presented in
a similar way as `describe-bindings' does, split into sections
defined by the types of the key bindings (minor and major modes,
global bindings, etc).
The default action executes a command as if the binding had been
entered, or narrows the commands according to a prefix key,
respectively.
The persistent action pops up a help buffer for the selected
command without quitting.
For key translation maps, the default actions are not very
useful, yet they are listed for completeness."
(interactive)
(let ((old-helm-full-frame helm-full-frame)
(helm-full-frame (and (not (minibufferp))
(memq helm-descbinds-window-style
'(same-window one-window))))
(helm-before-initialize-hook (if (and (not (minibufferp))
(eq helm-descbinds-window-style
'one-window))
(cons 'delete-other-windows
helm-before-initialize-hook)
helm-before-initialize-hook))
(enable-recursive-minibuffers t))
(setq helm-descbind--initial-full-frame old-helm-full-frame)
(helm :sources (helm-descbinds-sources
(or buffer (current-buffer)) prefix)
:buffer "*helm-descbinds*"
:resume 'noresume
:allow-nest t)))
(provide 'helm-descbinds)
;;; helm-descbinds.el ends here

View File

@ -0,0 +1,26 @@
;;; helm-describe-modes-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "helm-describe-modes" "helm-describe-modes.el"
;;;;;; (22536 51973 298163 29000))
;;; Generated autoloads from helm-describe-modes.el
(autoload 'helm-describe-modes "helm-describe-modes" "\
A convenient Helm version of `describe-mode'.
By default, it lists the major mode, active minor modes, and
inactive minor modes. Sources can be added or removed by
customizing `helm-describe-modes-function-list'.
\(fn)" t nil)
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; helm-describe-modes-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; -*- no-byte-compile: t -*-
(define-package "helm-describe-modes" "20160211.2118" "Helm interface to major and minor modes." '((helm "1.9") (cl-lib "0.5") (emacs "24.1")) :url "https://github.com/emacs-helm/helm-describe-modes" :keywords '("docs" "convenience"))

View File

@ -0,0 +1,185 @@
;;; helm-describe-modes.el --- Helm interface to major and minor modes. -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Tianxiang Xiong
;; Author: Tianxiang Xiong <tianxiang.xiong@gmail.com>
;; Package-Requires: ((helm "1.9") (cl-lib "0.5") (emacs "24.1"))
;; Package-Version: 20160211.2118
;; Keywords: docs, convenience
;; URL: https://github.com/emacs-helm/helm-describe-modes
;; Version: 1.0.0
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package provides a Helm interface to major and minor mode
;; information. It is intended as a replacement for `describe-mode',
;; `describe-minor-mode', and other related commands.
;;
;; This package is heavily inspired by the `helm-descbinds' package by
;; Taiki Sugawara. See: https://github.com/emacs-helm/helm-descbinds
;;; Usage:
;; Add the following to your init file to remap `describe-mode' to
;; `helm-describe-modes':
;;
;; (require 'helm-describe-modes)
;; (global-set-key [remap describe-mode] #'helm-describe-modes)
;;
;; For information about the Helm framework, see the the Helm project:
;; https://github.com/emacs-helm/helm
;;; Code:
(require 'cl-lib)
(require 'helm)
(declare-function helm-elisp--persistent-help "helm-elisp")
;;; Customize
(defgroup helm-describe-modes nil
"Helm interface to major and minor mode information."
:prefix "helm-describe-modes-"
:group 'helm)
(defcustom helm-describe-modes-function-list
'(helm-describe-modes-def-source--major-mode
helm-describe-modes-def-source--active-minor-modes
helm-describe-modes-def-source--inactive-minor-modes)
"List of functions that build Helm sources for `helm-describe-modes'."
:group 'helm-describe-modes
:type '(repeat (choice symbol)))
(defcustom helm-describe-modes-major-mode-actions
'(("Describe major mode" . helm-describe-function)
("Find major mode" . helm-find-function)
("Customize major mode" . customize-mode)
("Set as initial major mode" . (lambda (mode)
(customize-set-variable 'initial-major-mode
mode))))
"Actions for major mode."
:group 'helm-describe-modes
:type '(alist :key-type string :value-type function))
(defcustom helm-describe-modes-active-minor-mode-actions
'(("Describe minor mode" . describe-minor-mode)
("Find minor mode" . helm-find-function)
("Turn off minor mode(s)" . (lambda (_ignored)
(mapc (lambda (mode)
(funcall (helm-describe-modes--minor-mode-function mode) -1)) (helm-marked-candidates)))))
"Actions for active minor modes."
:group 'helm-describe-modes
:type '(alist :key-type string :value-type function))
(defcustom helm-describe-modes-inactive-minor-mode-actions
'(("Describe minor mode" . describe-minor-mode)
("Find minor mode" . helm-find-function)
("Turn on minor mode(s)" . (lambda (_ignored)
(mapc (lambda (mode)
(funcall (helm-describe-modes--minor-mode-function mode) t))
(helm-marked-candidates)))))
"Actions for inactive minor modes."
:group 'helm-describe-modes
:type '(alist :key-type string :value-type function))
;;; Helm sources
(defun helm-describe-modes--minor-mode-function (minor-mode)
"Get the symbol for MINOR-MODE's function.
This is usually the same symbol as MINOR-MODE."
(or (get minor-mode :minor-mode-function)
minor-mode))
(defun helm-describe-modes--minor-modes ()
"Return a list of all minor modes symbols with functions.
Some older packages do not register in `minor-mode-list', only in
`minor-mode-alist'. See `describe-mode' for more information."
(cl-remove-if-not (lambda (mode)
(fboundp (helm-describe-modes--minor-mode-function mode)))
(cl-remove-duplicates (append (mapcar #'car minor-mode-alist)
minor-mode-list))))
(defun helm-describe-modes--active-minor-modes ()
"Return a list of active minor modes.
A minor mode is assumed to be active if it has a value."
(cl-remove-if-not (lambda (mode)
(and (boundp mode)
(symbol-value mode)))
(helm-describe-modes--minor-modes)))
(defun helm-describe-modes-def-source--major-mode ()
"Return a `helm' source for the major mode."
(helm-build-sync-source "Major mode"
:action 'helm-describe-modes-major-mode-actions
:candidates (list major-mode)
:coerce 'intern-soft
:nomark t))
(defun helm-describe-modes-def-source--active-minor-modes ()
"Return a `helm' source for active minor modes."
(helm-build-sync-source "Active minor modes"
:action 'helm-describe-modes-active-minor-mode-actions
:candidates (helm-describe-modes--active-minor-modes)
:candidate-transformer (lambda (modes)
(sort modes #'string-lessp))
:coerce 'intern-soft
:persistent-action (lambda (mode)
(helm-elisp--persistent-help
mode 'describe-minor-mode))
:persistent-help "Describe minor mode"))
(defun helm-describe-modes-def-source--inactive-minor-modes ()
"Return a `helm' source for inactive minor modes.
This is the set of all minor modes excluding active minor modes.
See `helm-describe-modes--minor-modes' and
`helm-describe-modes--active-minor-modes' for more information."
(helm-build-sync-source "Inactive minor modes"
:action 'helm-describe-modes-inactive-minor-mode-actions
:candidates (cl-set-difference (helm-describe-modes--minor-modes)
(helm-describe-modes--active-minor-modes))
:candidate-transformer (lambda (modes)
(sort modes #'string-lessp))
:coerce 'intern-soft
:persistent-action (lambda (mode)
(helm-elisp--persistent-help
mode 'describe-minor-mode))
:persistent-help "Describe minor mode"))
;;; Autoloads
;;;###autoload
(defun helm-describe-modes ()
"A convenient Helm version of `describe-mode'.
By default, it lists the major mode, active minor modes, and
inactive minor modes. Sources can be added or removed by
customizing `helm-describe-modes-function-list'."
(interactive)
(helm :sources (mapcar #'funcall helm-describe-modes-function-list)
:buffer "*Helm Describe Modes*"))
;;; Provide
(provide 'helm-describe-modes)
;;; helm-describe-modes.el ends here

View File

@ -83,6 +83,8 @@
helm-ag
helm-chrome
helm-company
helm-descbinds
helm-describe-modes
helm-flycheck
helm-flyspell
helm-github-stars
@ -582,6 +584,10 @@
(lambda ()
(flyspell-mode 1))))
(use-package helm-descbinds)
(use-package helm-describe-modes)
;; Load my own functions
(load "gnu-c-header.el")
(load "toggle-window-split.el")