gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

novice+.el - extensions to GNU `novice.el'


From: Drew Adams
Subject: novice+.el - extensions to GNU `novice.el'
Date: Tue, 16 Jan 2001 21:35:20 -0500

;;; novice+.el --- Extensions to `novice.el'.
;; 
;; Emacs Lisp Archive Entry
;; Filename: novice+.el
;; Description: Extensions to `novice.el'.
;; Author: Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 1996-2001, Drew Adams, all rights reserved.
;; Created: Thu Jul 11 17:10:39 1996
;; Version: $Id: novice+.el,v 1.5 2001/01/09 01:53:37 dadams Exp $
;; Last-Updated: Mon Jan  8 17:53:29 2001
;;           By: dadams
;;     Update #: 81
;; Keywords: internal, help, local
;; Compatibility: GNU Emacs 20.x
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Commentary: 
;; 
;;    Extensions to `novice.el'.
;; 
;; 
;;  ***** NOTE: The following functions defined in `novice.el' have
;;              been REDEFINED HERE:
;;
;;  `disable-command', `enable-command' - 
;;     These now use `completing-read' in the interactive spec, with,
;;     as default, `symbol-nearest-point'.
;;
;;
;;  This file should be loaded after loading the standard GNU file
;;  `novice.el'.  So, in your `~/.emacs' file, do this:
;;  (eval-after-load "novice" '(require 'novice+))
;;
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Change log:
;; 
;; RCS $Log: novice+.el,v $
;; RCS Revision 1.5  2001/01/09 01:53:37  dadams
;; RCS Adapted file header for Emacs Lisp Archive.
;; RCS
;; RCS Revision 1.4  2001/01/03 17:42:06  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.3  2001/01/03 00:59:38  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.2  2000/11/28 20:30:12  dadams
;; RCS Optional require's via 3rd arg=t now.
;; RCS
;; RCS Revision 1.1  2000/09/14 17:23:23  dadams
;; RCS Initial revision
;; RCS
; Revision 1.3  1999/03/31  13:50:37  dadams
; Updated using version in Emacs version 34.
;
; Revision 1.2  1999/03/17  15:07:51  dadams
; Protect with fboundp.
;
; Revision 1.1  1997/03/20  16:18:03  dadams
; Initial revision
;
; Revision 1.2  1996/07/15  08:49:24  dadams
; (trivial)
;
; Revision 1.1  1996/07/11  15:26:45  dadams
; Initial revision
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; 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 2, 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; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Code:

(require 'cl) ;; when, unless

;; Cannot do (require 'novice) prior to version 20, because `novice.el'
;; does no `provide'.  Don't want to do a (load-library "novice") either,
;; for prior versions, because it wouldn't allow doing
;; (eval-after-load "novice" '(progn (require 'novice+)))
(when (>= 20 emacs-major-version) (require 'novice))

(require 'elect-mbuf nil t) ;; (no error if not found): completing-read
(require 'thingatpt nil t) ;; (no error if not found): symbol-at-point
(require 'thingatpt+ nil t) ;; (no error if not found): symbol-nearest-point


(provide 'novice+)

;;; Variable USER-INIT-FILE is free here (defined in `files.el').

;;;;;;;;;;;;;;;;;;;;;;;;


;; REPLACES ORIGINAL in `novice.el':
;; Uses `completing-read' in interactive spec, with `symbol-nearest-point'.
;; `symbol-nearest-point' is defined in `thingatpt+.el'.
;; `symbol-at-point' is defined in `thingatpt.el'.
;;;###autoload
(defun enable-command (command)
  "Allow COMMAND to be invoked without confirmation from now on.
Your `~/.emacs' file is altered so that this applies also to future
sessions.  See command `\\[disable-command]'."
  (interactive
   (let ((symb (cond ((fboundp 'symbol-nearest-point) (symbol-nearest-point))
                     ((fboundp 'symbol-at-point) (symbol-at-point))
                     (t nil)))
         (enable-recursive-minibuffers t))
     (list (intern (completing-read "Enable command: " obarray 'commandp nil
                                    (symbol-name symb) nil (symbol-name symb) 
t)))))
  (put command 'disabled nil)
  (save-excursion
    (set-buffer (find-file-noselect (substitute-in-file-name user-init-file)))
    (goto-char (point-min))
    (when (search-forward (concat "(put '" (symbol-name command) " ") nil t)
      (delete-region (progn (beginning-of-line) (point))
                     (progn (forward-line 1) (point))))
    ;; Explicitly enable, in case this command is disabled by default
    ;; or in case the code we deleted was actually a comment.
    (goto-char (point-max))
    (insert "\n(put '" (symbol-name command) " 'disabled nil)\n")
    (save-buffer)))


;; REPLACES ORIGINAL in `novice.el':
;; Uses `completing-read' in interactive spec, with `symbol-nearest-point'.
;; `symbol-nearest-point' is defined in `thingatpt+.el'.
;; `symbol-at-point' is defined in `thingatpt.el'.
;;;###autoload
(defun disable-command (command)
  "Require confirmation to execute COMMAND from now on.
Your `~/.emacs' file is altered so that this applies also to future
sessions.  See command `\\[enable-command]'."
  (interactive
   (let ((symb (cond ((fboundp 'symbol-nearest-point) (symbol-nearest-point))
                     ((fboundp 'symbol-at-point) (symbol-at-point))
                     (t nil)))
         (enable-recursive-minibuffers t))
     (list (intern (completing-read "Disable command: " obarray 'commandp nil
                                    (symbol-name symb) nil (symbol-name symb) 
t)))))
  (unless (commandp command) (error "Invalid command name `%s'." command))
  (put command 'disabled t)
  (save-excursion
   (set-buffer (find-file-noselect (substitute-in-file-name user-init-file)))
   (goto-char (point-min))
   (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
       (delete-region (progn (beginning-of-line) (point))
                      (progn (forward-line 1) (point))))
   (goto-char (point-max))
   (insert "\n(put '" (symbol-name command) " 'disabled t)\n")
   (save-buffer)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `novice+.el' ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]