diff options
author | Alex Kost <alezost@gmail.com> | 2014-08-27 16:44:17 +0400 |
---|---|---|
committer | Alex Kost <alezost@gmail.com> | 2014-09-03 23:50:35 +0400 |
commit | 457f60fa068c7becf60841daa2b6fc5121aedead (patch) | |
tree | 8cae5e141a6c5c643255b6777e19c063010cf6f0 /emacs/guix-history.el | |
parent | a423555d3c4314f8347d75b050d7daf6e594281f (diff) | |
download | guix-457f60fa068c7becf60841daa2b6fc5121aedead.tar guix-457f60fa068c7becf60841daa2b6fc5121aedead.tar.gz |
Add Emacs user interface.
* configure.ac (emacsuidir): New variable.
(AC_CONFIG_FILES): Add 'emacs/guix-init.el', 'emacs/guix-helper.scm'.
* Makefile.am: Include 'emacs.am'.
* emacs.am: New file.
* doc/emacs.texi: New file.
* doc/guix.texi: Include 'emacs.texi'.
* emacs/guix-backend.el: New file.
* emacs/guix-base.el: New file.
* emacs/guix-helper.scm.in: New file.
* emacs/guix-history.el: New file.
* emacs/guix-info.el: New file.
* emacs/guix-init.el.in: New file.
* emacs/guix-list.el: New file.
* emacs/guix-main.scm: New file.
* emacs/guix-utils.el: New file.
* emacs/guix.el: New file.
Diffstat (limited to 'emacs/guix-history.el')
-rw-r--r-- | emacs/guix-history.el | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/emacs/guix-history.el b/emacs/guix-history.el new file mode 100644 index 0000000000..5d301a689e --- /dev/null +++ b/emacs/guix-history.el @@ -0,0 +1,92 @@ +;;; guix-history.el --- History of buffer information + +;; Copyright © 2014 Alex Kost <alezost@gmail.com> + +;; This file is part of GNU Guix. + +;; GNU Guix 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. + +;; GNU Guix 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 file provides support for history of buffers similar to the +;; history of a `help-mode' buffer. + +;;; Code: + +(require 'cl-macs) + +(defvar-local guix-history-stack-item nil + "Current item of the history. +A list of the form (FUNCTION [ARGS ...]). +The item is used by calling (apply FUNCTION ARGS).") +(put 'guix-history-stack-item 'permanent-local t) + +(defvar-local guix-history-back-stack nil + "Stack (list) of visited items. +Each element of the list has a form of `guix-history-stack-item'.") +(put 'guix-history-back-stack 'permanent-local t) + +(defvar-local guix-history-forward-stack nil + "Stack (list) of items visited with `guix-history-back'. +Each element of the list has a form of `guix-history-stack-item'.") +(put 'guix-history-forward-stack 'permanent-local t) + +(defvar guix-history-size 0 + "Maximum number of items saved in history. +If 0, the history is disabled.") + +(defun guix-history-add (item) + "Add ITEM to history." + (and guix-history-stack-item + (push guix-history-stack-item guix-history-back-stack)) + (setq guix-history-forward-stack nil + guix-history-stack-item item) + (when (>= (length guix-history-back-stack) + guix-history-size) + (setq guix-history-back-stack + (cl-loop for elt in guix-history-back-stack + for i from 1 to guix-history-size + collect elt)))) + +(defun guix-history-replace (item) + "Replace current item in history with ITEM." + (setq guix-history-stack-item item)) + +(defun guix-history-goto (item) + "Go to the ITEM of history. +ITEM should have the form of `guix-history-stack-item'." + (or (listp item) + (error "Wrong value of history element")) + (setq guix-history-stack-item item) + (apply (car item) (cdr item))) + +(defun guix-history-back () + "Go back to the previous element of history in the current buffer." + (interactive) + (or guix-history-back-stack + (user-error "No previous element in history")) + (push guix-history-stack-item guix-history-forward-stack) + (guix-history-goto (pop guix-history-back-stack))) + +(defun guix-history-forward () + "Go forward to the next element of history in the current buffer." + (interactive) + (or guix-history-forward-stack + (user-error "No next element in history")) + (push guix-history-stack-item guix-history-back-stack) + (guix-history-goto (pop guix-history-forward-stack))) + +(provide 'guix-history) + +;;; guix-history.el ends here |