Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

119 lines (100 sloc) 4.52 kb
;;; memo-pop.el --- helps you to take notes easily on Emacs. Only one key action to work.
;; Copyright (C) 2009, 2010, 2011, 2012 Kazuo Yagi
;; Author: Kazuo YAGI <kazuo.yagi@gmail.com>
;; Maintainer: Kazuo YAGI <kazuo.yagi@gmail.com>
;; Created: 2009-06-03 11:21:23
;; Last-Updated: 2012-10-24 17:37:48
;; Keywords: memo, notes, text
;; Compatibility: GNU Emacs 23.x, 24.x
;; 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 is a utility which helps you pop up and pop out a specifc file buffer
;; window easily. Just do M-x memo-pop, and it is strongly recommmended
;; to assign one hot-key to this function.
;;
;; I hope this is useful for you, and ENJOY YOUR HAPPY HACKING!
;;
;;; Configration:
;;
;; You just have only to set hot-keys to your most visiting file and
;; type that hot-keys to visit that file and return from it promptly.
;;
;; A configuration sample for your .emacs is as follows.
;; (require 'memo-pop)
;; (memo-pop-set-key-and-file [f1] "/Users/kyagi/memo/memo.txt")
;; (memo-pop-set-key-and-file [f2] "/Users/kyagi/memo/dict.txt")
;; (memo-pop-set-key-and-file [f3] (concat "/Users/kyagi/diary/"
;; (format-time-string "%Y-%m-%d") ".txt"))
;; If 100, memo-pop use the whole of selected window, not spliting.
;; (memo-pop-set-window-height 60)
;; The position for memo-pop window. You can choose "top" or "bottom".
;; (memo-pop-set-window-position "bottom")
;;; Code:
(require 'cl)
(defvar memo-pop-last-buffer nil)
(defvar memo-pop-last-window nil)
(defvar memo-pop-file-path nil)
(defvar memo-pop-file-buffer nil)
(defvar memo-pop-window-height 60) ; percentage for pop up buffer window height
(defvar memo-pop-window-position "bottom")
(defun memo-pop-set-key-and-file (key path)
(interactive "kInput a key-sequence and return: \nsInput path you want to visit promptly: ")
(lexical-let ((key key)(path path))
(global-set-key key (lambda () (interactive)
(memo-pop path))))
(message "%s is assigned to %s now" (key-description key) path))
(defun memo-pop-set-window-height (number)
(interactive "nInput the number for the percentage of \
selected window height (10-90): ")
(setq memo-pop-window-height number))
(defun memo-pop-set-window-position (position)
(interactive "sInput the position for memo-pop (top|bottom): ")
(setq memo-pop-window-position position))
(defun memo-pop (path)
(interactive)
(setq memo-pop-file-path path)
(setq memo-pop-file-buffer (file-name-nondirectory path))
(if (equal (buffer-name) memo-pop-file-buffer)
(memo-pop-out)
(memo-pop-up)))
(defun memo-pop-up ()
(let ((w (get-buffer-window memo-pop-file-buffer)))
(if w
(select-window w)
(progn ; save memo-pop-last-buffer and memo-pop-last-window to return
(setq memo-pop-last-buffer (buffer-name))
(setq memo-pop-last-window (selected-window))
(if (not (eq memo-pop-window-height 100))
(progn
(split-window (selected-window)
(if (string= memo-pop-window-position "bottom")
(round (* (window-height)
(/ (- 100 memo-pop-window-height) 100.0)))
(round (* (window-height) (/ memo-pop-window-height 100.0)))))
(if (string= memo-pop-window-position "bottom")
(other-window 1))))
(if (not (get-buffer memo-pop-file-buffer))
(find-file memo-pop-file-path)
(switch-to-buffer memo-pop-file-buffer))))))
(defun memo-pop-out ()
(if (not (eq memo-pop-window-height 100))
(progn
(save-buffer)
(delete-window)
(if (string= memo-pop-window-position "bottom")
(select-window memo-pop-last-window))))
(switch-to-buffer memo-pop-last-buffer))
(defun memo-pop-window-position-p ()
memo-pop-window-position)
(provide 'memo-pop)
;;; memo-pop.el ends here.
Jump to Line
Something went wrong with that request. Please try again.