]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
Capitalization in comment.
[gnu-emacs] / lisp / subr.el
index ff9d9e5782467dbf8e1cfa6844beecf040bc42a5..3125a577fd2d883a0c8923633b3437d3d79cbde0 100644 (file)
@@ -35,6 +35,8 @@ Each element of this list holds the arguments to one call to `defcustom'.")
 \f
 ;;;; Lisp language features.
 
+(defalias 'not 'null)
+
 (defmacro lambda (&rest cdr)
   "Return a lambda expression.
 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
@@ -664,7 +666,6 @@ Please convert your programs to use the variable `baud-rate' directly."
 (defalias 'string= 'string-equal)
 (defalias 'string< 'string-lessp)
 (defalias 'move-marker 'set-marker)
-(defalias 'not 'null)
 (defalias 'rplaca 'setcar)
 (defalias 'rplacd 'setcdr)
 (defalias 'beep 'ding) ;preserve lingual purity
@@ -846,21 +847,23 @@ If FILE is already loaded, evaluate FORM right now.
 It does nothing if FORM is already on the list for FILE.
 FILE must match exactly.  Normally FILE is the name of a library,
 with no directory or extension specified, since that is how `load'
-is normally called."
-  ;; Make sure `load-history' contains the files dumped with Emacs
-  ;; for the case that FILE is one of the files dumped with Emacs.
-  (load-symbol-file-load-history)
-  ;; Make sure there is an element for FILE.
-  (or (assoc file after-load-alist)
-      (setq after-load-alist (cons (list file) after-load-alist)))
-  ;; Add FORM to the element if it isn't there.
+is normally called.
+FILE can also be a feature (i.e. a symbol), in which case FORM is
+evaluated whenever that feature is `provide'd."
   (let ((elt (assoc file after-load-alist)))
-    (or (member form (cdr elt))
-       (progn
-         (nconc elt (list form))
-         ;; If the file has been loaded already, run FORM right away.
-         (and (assoc file load-history)
-              (eval form)))))
+    ;; Make sure there is an element for FILE.
+    (unless elt (setq elt (list file)) (push elt after-load-alist))
+    ;; Add FORM to the element if it isn't there.
+    (unless (member form (cdr elt))
+      (nconc elt (list form))
+      ;; If the file has been loaded already, run FORM right away.
+      (if (if (symbolp file)
+             (featurep file)
+           ;; Make sure `load-history' contains the files dumped with
+           ;; Emacs for the case that FILE is one of them.
+           (load-symbol-file-load-history)
+           (assoc file load-history))
+         (eval form))))
   form)
 
 (defun eval-next-after-load (file)
@@ -990,7 +993,7 @@ With optional non-nil ALL, force redisplay of all mode-lines."
   (if all (save-excursion (set-buffer (other-buffer))))
   (set-buffer-modified-p (buffer-modified-p)))
 
-(defun momentary-string-display (string pos &optional exit-char message) 
+(defun momentary-string-display (string pos &optional exit-char message)
   "Momentarily display STRING in the buffer at POS.
 Display remains until next character is typed.
 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
@@ -1034,6 +1037,41 @@ If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
       (set-buffer-modified-p modified))))
 
 \f
+;;;; Overlay operations
+
+(defun copy-overlay (o)
+  "Return a copy of overlay O."
+  (let ((o1 (make-overlay (overlay-start o) (overlay-end o)
+                         ;; FIXME: there's no easy way to find the
+                         ;; insertion-type of the two markers.
+                         (overlay-buffer o)))
+       (props (overlay-properties o)))
+    (while props
+      (overlay-put o1 (pop props) (pop props)))
+    o1))
+
+(defun remove-overlays (beg end name val)
+  "Clear BEG and END of overlays whose property NAME has value VAL.
+Overlays might be moved and or split."
+  (if (< end beg)
+      (setq beg (prog1 end (setq end beg))))
+  (save-excursion
+    (dolist (o (overlays-in beg end))
+      (when (eq (overlay-get o name) val)
+       ;; Either push this overlay outside beg...end
+       ;; or split it to exclude beg...end
+       ;; or delete it entirely (if it is contained in beg...end).
+       (if (< (overlay-start o) beg)
+           (if (> (overlay-end o) end)
+               (progn
+                 (move-overlay (copy-overlay o)
+                               (overlay-start o) beg)
+                 (move-overlay o end (overlay-end o)))
+             (move-overlay o (overlay-start o) beg))
+         (if (> (overlay-end o) end)
+             (move-overlay o end (overlay-end o))
+           (delete-overlay o)))))))
+
 ;;;; Miscellanea.
 
 ;; A number of major modes set this locally.
@@ -1204,6 +1242,13 @@ See also `with-temp-file' and `with-output-to-string'."
           (buffer-string)
         (kill-buffer nil)))))
 
+(defmacro with-local-quit (&rest body)
+  "Execute BODY with `inhibit-quit' temporarily bound to nil."
+  `(condition-case nil
+       (let ((inhibit-quit nil))
+        ,@body)
+     (quit (setq quit-flag t))))
+
 (defmacro combine-after-change-calls (&rest body)
   "Execute BODY, but don't call the after-change functions till the end.
 If BODY makes changes in the buffer, they are recorded
@@ -1445,14 +1490,11 @@ and replace a sub-expression, e.g.
 
 (defun make-syntax-table (&optional oldtable)
   "Return a new syntax table.
-If OLDTABLE is non-nil, copy OLDTABLE.
-Otherwise, create a syntax table which inherits from the
-`standard-syntax-table'."
-  (if oldtable
-      (copy-syntax-table oldtable)
-    (let ((table (make-char-table 'syntax-table nil)))
-      (set-char-table-parent table (standard-syntax-table))
-      table)))
+Create a syntax table which inherits from OLDTABLE (if non-nil) or
+from `standard-syntax-table' otherwise."
+  (let ((table (make-char-table 'syntax-table nil)))
+    (set-char-table-parent table (or oldtable (standard-syntax-table)))
+    table))
 
 (defun add-to-invisibility-spec (arg)
   "Add elements to `buffer-invisibility-spec'.
@@ -1528,10 +1570,13 @@ configuration."
        (eq (car object) 'frame-configuration)))
 
 (defun functionp (object)
-  "Non-nil if OBJECT is a type of object that can be called as a function."
-  (or (subrp object) (byte-code-function-p object)
-      (eq (car-safe object) 'lambda)
-      (and (symbolp object) (fboundp object))))
+  "Non-nil iff OBJECT is a type of object that can be called as a function."
+  (or (and (symbolp object) (fboundp object)
+          (setq object (indirect-function object))
+          (eq (car-safe object) 'autoload)
+          (not (car-safe (cdr-safe (cdr-safe (cdr-safe (cdr-safe object)))))))
+      (subrp object) (byte-code-function-p object)
+      (eq (car-safe object) 'lambda)))
 
 (defun interactive-form (function)
   "Return the interactive form of FUNCTION.