Q:

Make parts of a working buffer read-only

Is it possible to make only parts of a buffer read-only? 
Say I have set two marks or line-numbers in the buffer and I would like to make everything between those two marks or line-numbers as read-only. 
The function (read-only-mode) applies to the entire buffer but not to 
parts of it. 
Also, if possible, I would like the read-only parts of a buffer marked 
with a different background color say light beige. 

A:

(defface my-read-only '((default . (:background "beige")))
  "Face for `my-read-only-region'")

(defun my-read-only-region (begin end)
  "Make the marked region read-only.  See also `my-writeable-region'.

Read-only text is given the face `my-read-only'."
  (interactive "r")
  (let ((inhibit-read-only t))
    (with-silent-modifications
      (add-text-properties begin end '(read-only t))
      (let ((overlay (make-overlay begin end)))
        (overlay-put overlay 'my-type 'read-only)
        (overlay-put overlay 'face 'my-read-only)))))

(defun my-writeable-region (begin end)
  "Make the marked region writeable.  See also `my-read-only-region'."
  (interactive "r")
  (let ((inhibit-read-only t))
    (with-silent-modifications
      (remove-text-properties begin end '(read-only t))
      (remove-overlays begin end 'my-type 'read-only))))

