GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


d-readonly.el

    

;;; d-readonly.el --- A readonly lock to prevent accidental editing of certain files

;; Copyright (C) 2013 Davin Pearson
;;
;; Author/Maintainer: Davin Max Pearson <http://davin.50webs.com>
;; Keywords: read-only file protection
;; Version: 1.0

;;; Commentary:

;; This file is not part of GNU Emacs.

;; This file prevents you from accidentally editing certain precious
;; files.  To override this feature, press f7 to toggle the read only
;; status of a buffer.

;;; Limitation of Warranty

;; 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 3 of the License, 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 detail.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs, see the file COPYING.  If not, see:
;;
;; <http://www.gnu.org/licenses/gpl-3.0.txt>.


;;; Install Instructions:
;; See the following URL for the latest info and a tarball:
;;
;; <http://davin.50webs.com/research/2010/mopa2e2.html#d-readonly>
;;
;; Then untar the tarball to a folder pointed to by the Emacs variable
;; load-path and add the following line to your ~/.emacs file.
;;
;; (require 'd-readonly)

;;; Known Bugs:

;; None!

;;; Code:

;; NOTE: bug fix for emacs 23.* lacking this function
(if (not (fboundp 'read-only-mode))
    (defun read-only-mode (arg &rest args)
      (interactive)
      (read-only-mode arg)))

(when (and (boundp 'prefs-home-emacs-p)
           prefs-home-emacs-p
           (not noninteractive))
  (add-hook 'find-file-hook 'd-readonly)
  (add-hook 'dired-mode-hook 'd-readonly)
  ;;(add-hook 'dired-mode-hook 'd-ding)
  )

(defun d-readonly ()
  " abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz"
  (save-match-data
    ;;(d-beeps "Prince / Parade / Under The Cherry Moon")
    (let ((file (or (buffer-file-name) dired-directory)))
      ;;(debug "Ramjet")
      ;;(message "file=%s" file)
      (if (and (file-directory-p file) (not (string-match "/$" file)))
          (setq file (concat file "/")))
      ;;(d-beeps "* file=%s" file)
      (cond

((string-match (getenv "HOME") file)
        ;;(d-beeps "foo")
        (read-only-mode -1)
        (setq truncate-lines t))

((eq major-mode 'dired-mode)
        ;;(d-beeps "R.E.M. / Reckoning / (Don't Go Back To) Rockville, dired-mode")
        (read-only-mode 1)
        (setq truncate-lines t)
        )

;;(t
       ;; (d-beeps "Public Enemy / Apocalypse 91... The Enemy Strikes Black / Lost At Birth"))

       ((and (null (buffer-file-name))
             (string= (buffer-name) "*Backtrace*"))
        (setq truncate-lines nil))

((and (buffer-file-name)
             (string= (file-name-nondirectory (buffer-file-name)) "TAGS"))
        ;;(debug "Calamansi")
        (read-only-mode 1))

((and (buffer-file-name)
             (string-match ".*\\.dir$" (file-name-nondirectory (buffer-file-name))))
        (read-only-mode 1))

((string-match "\\.temp$" file)
        (read-only-mode 1))

((string= (buffer-name) " *d-speedbar*")
        (read-only-mode 1))

((string-match "/jtw-tutorials" default-directory)
        (read-only-mode -1))

((string-match "/J.T.W/" default-directory)
        (read-only-mode -1))

((string-match "/Downloads/" file)
        (setq truncate-lines t)
        (read-only-mode 1))

((string-match "/lisp\\+\\+-projects/" file)
        ;;(d-beeps "c++-projects file=%s" file)
        (setq truncate-lines t)
        (read-only-mode -1)
        )

((or (string-match "~/c2java/" file)
            (string-match "hairy-lemon/src/50webs-com/research/2015/c2java-1\\.12/" file))
        (read-only-mode -1))

((string-match "hairy-lemon/src/50webs-com/research/2015/c2java-1\\.[0-9]+/" file)
        (read-only-mode 1))

((string-match "/java-projects/" file)
        (setq truncate-lines t)
        (setq tab-width 5)
        (read-only-mode -1))

((string-match "/imported-stuff/" file)
        (read-only-mode 1))

((string-match "/var/www/" file)
        (read-only-mode -1))

((string-match "dlisp/d-snaffle-database-full-list.el" file)
        (read-only-mode 1))

((string-match "^d:/home/hairy-lemon/output/index.html$" file)
        (read-only-mode -1))

((string-match "^log\\.\\(txt\\|el\\)$" file)
        (d-beeps "Black Sabbath / Killing Yourself To Live, log.el")
        (setq truncate-lines t)
        (setq tab-width 3)
        (read-only-mode -1))

((string-match "[a-z]:/wamp/" file)
        ;;(d-beeps "c:/wamp/")
        (setq truncate-lines t)
        (setq tab-width 3)
        (read-only-mode -1))

((string-match "e:/Driver Pack Solution/" file)
        ;;(d-beeps "e:/Driver Pack Solution/")
        (setq truncate-lines t)
        (setq tab-width 3)
        (read-only-mode 1))

((let ((case-fold-search t))
          (and (string-match "/output/" file)
               (string-match "\\.html?$" file)))
        (read-only-mode 1))

((let ((case-fold-search t))
          (string-match "/hairy-lemon/" file))
        (read-only-mode -1))

((string-match "allegro" file)
        (read-only-mode 1))

((string-match "wordpress" file)
        (read-only-mode -1))

((string-match "/Program Files/" file)
        (read-only-mode 1))

((and prefs-home-emacs-p (string-match "/ro[a-z]*/" file))
        (read-only-mode 1))

((string-match "\\.\\(gz\\|rpm\\|tar\\|tgz\\|zip\\)$" file)
        (read-only-mode 1))

((string-match "\\.\\(class\\|dll\\|exe\\|lnk\\|o\\)$" file)
        (read-only-mode 1))

((string-match "\\.\\(dvi\\|gif\\|jpg\\|mpg\\|pdf\\|ps\\|tga\\)$" file)
        (read-only-mode 1))

((string-match "[a-z]:/" file)
        (read-only-mode 1))

((string-match "/dlisp/" file)
        (read-only-mode -1))

(t
        (read-only-mode 1))))))

(defun d-read-only-mode ()
  (interactive)
  (if buffer-read-only
      (read-only-mode -1)
    (read-only-mode 1)))

(when prefs-davins-keybindings-online-p
  (global-set-key [f7] 'd-read-only-mode)
  )

(provide 'd-readonly)
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Mon May 6 01:56:58 NZST 2019
Best viewed at 800x600 or above resolution.
© Copyright 1999-2019 Davin Pearson.
Please report any broken links to