* Howto change [enter] behaviour?
@ 2003-02-14 8:09 François Fleuret
2003-02-14 18:46 ` Kevin Rodgers
2003-02-15 5:24 ` Pascal Bourguignon
0 siblings, 2 replies; 3+ messages in thread
From: François Fleuret @ 2003-02-14 8:09 UTC (permalink / raw)
Hi,
I am writing a major mode to play mp3s (I know something like this
already exists, but mine is simpler and it was more an exercice in
elisp than a real project ... anyway). My only problem so far is how
to change the behaviour of the [enter] key. How am I supposed to do
that ?
Thanks in advance,
FF
;; -*-Emacs-Lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This program is free software; you can redistribute it and/or ;;
;; modify it under the terms of the GNU General Public License ;;
;; version 2 as published by the Free Software Foundation. ;;
;; ;;
;; 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. ;;
;; ;;
;; Written and (c) by François Fleuret ;;
;; Contact <francois.fleuret@noos.fr> for comment & bug reports ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; A very (I mean it) simple mp3 handling mode for emacs. Tested with
;; emacs-21.2 on GNU/Linux Debian.
;; Just add in your .emacs :
;;
;; (load "mp3play.el")
;; (setq mp3play-playlist '("~/my_mp3_dir" "/nfs/stuff/my_other_dir"))
;;
;; and invoke the player with M-x mp3play. You can also add :
;;
;; (define-key global-map [(meta \\)] 'mp3play)
;;
;; So that meta-\ goes to mp3play. Type 'h' for help, ' ' to play a
;; song and 'q' to burry the buffer.
(defvar mp3play-mode-map nil "Keymap for mp3play mode")
(defvar mp3play-playlist nil "List of the directories containing the mp3s for mp3play")
(defvar mp3play-player "mpg321" "Program to use to play mp3s")
(defvar mp3play-mode-hook nil "List of hook functions run by `mp3play-mode' (see `run-hooks')")
(setq mpg321-process nil)
(defun mp3play-kill () (interactive)
(kill-buffer (get-buffer "*mp3play*")))
(defun mp3play-quit () (interactive)
(bury-buffer))
(defun mp3play-help () (interactive)
(message "<space> play, <h> help, <n> next, <k> kill, <p> previous, <q> quit, <r> refresh list, <s> stop, <?> properties"))
(defun mp3play-play () "Starts mpg321 with the mp3 at the point" (interactive)
(let ((filename (get-text-property (point) 'filename)))
(when filename
(when mpg321-process
(delete-process mpg321-process)
(message "Stoping current song!")
(sleep-for 0.1))
(setq mpg321-process (start-process "mp3player" nil mp3play-player filename))
(sleep-for 0.1)
(when (not (eq (process-status mpg321-process) 'run))
(message (concat mp3play-player " Error! (sound device already in use ? non-existing file ?)"))
(setq mpg321-process nil))
(when mpg321-process
(message (format "Play \"%s\"" filename)))
)))
(defun mp3play-stop () (interactive)
(if (not mpg321-process) (message "Not playing!")
(delete-process mpg321-process)
(message "Stopped")
(setq mpg321-process nil))
)
;; Handling of properties
(defun mp3play-current-filename ()
(get-text-property (point) 'filename))
(defun mp3play-show-properties ()
(interactive)
(message (format "File \"%s\"" (mp3play-current-filename)))
)
;; (defun mp3play-set-properties (filename &rest l)
;; (let ((start (text-property-any (point-min) (point-max) 'filename filename))
;; (end (and start (next-single-property-change start 'filename))))
;; (if start
;; (eval `(add-text-properties start end ,@l)))))
;; (defun mp3play-line-string (props)
;; )
;; Here we add a new line with a given filename. Remove existing lines
;; with the same filename property
(defun mp3play-add-file (filename)
(when (file-regular-p filename)
(with-current-buffer (get-buffer "*mp3play*")
(let ((start (text-property-any (point-min) (point-max) 'filename filename)))
(if start
(progn
(goto-char start)
(kill-region (line-beginning-position) (1+ (line-end-position))))
(end-of-buffer)))
(let ((s (format "%s\n" (file-name-nondirectory filename))))
(add-text-properties 0 (1- (length s))
(list 'filename filename)
s)
(insert s))
))
)
(defun mp3play-add-directory (dir) (interactive)
(mapc (lambda (filename) ()
(mp3play-add-file (command-line-normalize-file-name (concat dir "/" filename))))
(directory-files dir))
t)
(defun mp3play-refresh-list () (interactive)
(switch-to-buffer (get-buffer "*mp3play*"))
(kill-region (point-min) (point-max))
(mapc (lambda (dir) () (mp3play-add-directory (expand-file-name dir)))
mp3play-playlist)
(goto-char (point-min))
)
(defun mp3play-mode ()
"Major mode to play mp3s taken in various directories"
(interactive)
(unless mp3play-mode-map
(setq mp3play-mode-map (make-keymap))
(suppress-keymap mp3play-mode-map)
(define-key mp3play-mode-map "n" 'next-line)
(define-key mp3play-mode-map "p" 'previous-line)
(define-key mp3play-mode-map "q" 'mp3play-quit)
(define-key mp3play-mode-map "k" 'mp3play-kill)
(define-key mp3play-mode-map " " 'mp3play-play)
(define-key mp3play-mode-map "r" 'mp3play-refresh-list)
(define-key mp3play-mode-map "s" 'mp3play-stop)
(define-key mp3play-mode-map "h" 'mp3play-help)
(define-key mp3play-mode-map "?" 'mp3play-show-properties)
(define-key mp3play-mode-map "\C-m" 'next-line)
)
(kill-all-local-variables)
(use-local-map mp3play-mode-map)
(setq mode-name "Mp3play")
(setq major-mode 'mp3play-mode)
(run-hooks 'mp3play-mode-hook)
)
(defun mp3play () "Switches to the mp3play buffer, creates it if
necessary. This buffer contains the list of all the mp3s from the
directories listed in `mp3play-playlist'. You can invoke mpg321 on a
given mp3 by typing <space> on the mp3 in this buffer. Use 'q' to
burry the buffer, and 'k' to kill it."
(interactive)
(if (not (and (boundp 'mp3play-playlist) mp3play-playlist))
(message "No playlist in mp3play-playlist!")
(if (get-buffer "*mp3play*")
(switch-to-buffer (get-buffer "*mp3play*"))
(switch-to-buffer (get-buffer-create "*mp3play*"))
(mp3play-mode)
(mp3play-refresh-list))
)
)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Howto change [enter] behaviour?
2003-02-14 8:09 Howto change [enter] behaviour? François Fleuret
@ 2003-02-14 18:46 ` Kevin Rodgers
2003-02-15 5:24 ` Pascal Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2003-02-14 18:46 UTC (permalink / raw)
François Fleuret wrote:
> I am writing a major mode to play mp3s (I know something like this
> already exists, but mine is simpler and it was more an exercice in
> elisp than a real project ... anyway). My only problem so far is how
> to change the behaviour of the [enter] key. How am I supposed to do
> that ?
Doesn't what you already have work (i.e. call next-line)? If not, what does
the Enter key do in your mode?
> (defun mp3play-mode ()
> "Major mode to play mp3s taken in various directories"
> (interactive)
>
> (unless mp3play-mode-map
> (setq mp3play-mode-map (make-keymap))
> (suppress-keymap mp3play-mode-map)
> (define-key mp3play-mode-map "n" 'next-line)
> (define-key mp3play-mode-map "p" 'previous-line)
> (define-key mp3play-mode-map "q" 'mp3play-quit)
> (define-key mp3play-mode-map "k" 'mp3play-kill)
> (define-key mp3play-mode-map " " 'mp3play-play)
> (define-key mp3play-mode-map "r" 'mp3play-refresh-list)
> (define-key mp3play-mode-map "s" 'mp3play-stop)
> (define-key mp3play-mode-map "h" 'mp3play-help)
> (define-key mp3play-mode-map "?" 'mp3play-show-properties)
> (define-key mp3play-mode-map "\C-m" 'next-line)
> )
>
> (kill-all-local-variables)
>
> (use-local-map mp3play-mode-map)
> (setq mode-name "Mp3play")
> (setq major-mode 'mp3play-mode)
> (run-hooks 'mp3play-mode-hook)
>
> )
--
<a href="mailto:<kevin.rodgers@ihs.com>">Kevin Rodgers</a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Howto change [enter] behaviour?
2003-02-14 8:09 Howto change [enter] behaviour? François Fleuret
2003-02-14 18:46 ` Kevin Rodgers
@ 2003-02-15 5:24 ` Pascal Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: Pascal Bourguignon @ 2003-02-15 5:24 UTC (permalink / raw)
francois.fleuret@noos.fr (François Fleuret) writes:
> Hi,
>
> I am writing a major mode to play mp3s (I know something like this
> already exists, but mine is simpler and it was more an exercice in
> elisp than a real project ... anyway). My only problem so far is how
> to change the behaviour of the [enter] key. How am I supposed to do
> that ?
>
> Thanks in advance,
Why do you ask if you already know that?
> (define-key mp3play-mode-map "n" 'next-line)
> (define-key mp3play-mode-map "p" 'previous-line)
> (define-key mp3play-mode-map "q" 'mp3play-quit)
> (define-key mp3play-mode-map "k" 'mp3play-kill)
> (define-key mp3play-mode-map " " 'mp3play-play)
> (define-key mp3play-mode-map "r" 'mp3play-refresh-list)
> (define-key mp3play-mode-map "s" 'mp3play-stop)
> (define-key mp3play-mode-map "h" 'mp3play-help)
> (define-key mp3play-mode-map "?" 'mp3play-show-properties)
> (define-key mp3play-mode-map "\C-m" 'next-line)
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-02-15 5:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-14 8:09 Howto change [enter] behaviour? François Fleuret
2003-02-14 18:46 ` Kevin Rodgers
2003-02-15 5:24 ` Pascal Bourguignon
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.