From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: francois.fleuret@noos.fr (=?iso-8859-1?q?Fran=E7ois?= Fleuret) Newsgroups: gmane.emacs.help Subject: Howto change [enter] behaviour? Date: 14 Feb 2003 09:09:51 +0100 Organization: Noos Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87fzqr1dww.fsf@noos.fr> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1045211108 4549 80.91.224.249 (14 Feb 2003 08:25:08 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 14 Feb 2003 08:25:08 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18jb9e-0001Aw-00 for ; Fri, 14 Feb 2003 09:25:06 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18jbAE-0002I5-07 for gnu-help-gnu-emacs@m.gmane.org; Fri, 14 Feb 2003 03:25:42 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!nntp.cs.ubc.ca!freenix!teaser.fr!noos.fr!not-for-mail Original-Newsgroups: gnu.emacs.help X-Attribution: FF User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Lines: 186 Original-NNTP-Posting-Date: 14 Feb 2003 08:22:31 GMT Original-NNTP-Posting-Host: 81.67.17.162 Original-X-Trace: 1045210951 news.noos.fr 21148 81.67.17.162 Original-X-Complaints-To: abuse@noos.fr Original-Xref: shelby.stanford.edu gnu.emacs.help:110170 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:6673 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6673 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 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 " play, help, next, kill,

previous, quit, refresh list, 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 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)) ) )