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-electric.el

    

;;; d-electric.el --- An improved electric-buffer-list function
;; Copyright (C) 2006-2015 Davin Pearson

;; Emacs Lisp Archive Entry
;; Filename: d-electric.el
;; Author/Maintainer: Davin Max Pearson <http://davin.50webs.com>
;; Version: 1.17
;; Keywords: Electric Buffer List

;;; Commentary:

;; This file is not part of GNU Emacs.

;;; 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-electric>
;;
;; 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-electric)

;;; Known Bugs:

;; None so far!

;;; Code:

(setq prefs-advanced-user-p t)
(require 'early-bindings)

(defun d-electric-buffer-list ()
  (interactive)
  ;;(save-window-excursion
  ;;(d-delete-speedbar-window)
  ;;(delete-other-windows)
  (call-interactively 'electric-buffer-list)
  ;;(bury-buffer)
  ;;(bury-buffer)
  ;;(d-beeps "Calamansi")
  ;;(electric-buffer-list 123)
  )

(when prefs-davins-keybindings-online-p
  (global-set-key [insert]           'd-electric-buffer-list)
  (global-set-key [(control insert)] 'd-electric-buffer-list)
  (global-set-key [(shift insert)]   'd-electric-buffer-list)
  (global-set-key [pause]            'd-electric-buffer-list)
  )

(setq d-electric--buffer-to-choose nil)

(defadvice electric-buffer-list (before d-electric activate)
  (push-mark (point) 'no-msg)
  (let* ((list (mapcar 'buffer-name (buffer-list)))
         (ptr  list))
    (while (or (d-is-buffer-visible (car ptr)) (and (car ptr) (= ?\ (aref (car ptr) 0))))
      (setq ptr (cdr ptr)))
    (setq d-electric--buffer-to-choose (car ptr))
  ))

;; (d-ding)
(defun d-ding ()
  (let ((visible-bell nil))
    (ding)))

(defun d-electric-hook ()
  "My own Electric Buffer Menu stuff.  Currently binds some convenience keys."
  (save-match-data
    (if (fboundp 'd-delete-speedbar-window) (d-delete-speedbar-window))
    (delete-other-windows)
    (define-key electric-buffer-menu-mode-map [up]       'previous-line)
    (define-key electric-buffer-menu-mode-map [down]     'next-line)
    (define-key electric-buffer-menu-mode-map [next]     'scroll-up)
    (define-key electric-buffer-menu-mode-map [previous] 'scroll-down)
    (define-key electric-buffer-menu-mode-map [left]     'scroll-right)
    (define-key electric-buffer-menu-mode-map [right]    'scroll-left)
    (define-key electric-buffer-menu-mode-map [insert]   'd-Electric-buffer-menu-select)
    (define-key electric-buffer-menu-mode-map [f12]      'd-Electric-buffer-menu-select)
    (define-key electric-buffer-menu-mode-map [return]   'd-Electric-buffer-menu-select)
    (define-key electric-buffer-menu-mode-map [pause]    'd-Electric-buffer-menu-select)
    (define-key electric-buffer-menu-mode-map [kp-enter] 'kp-enter)
    (assert (get-buffer "*Buffer List*"))
    (assert (string= (buffer-name) "*Buffer List*"))
    (read-only-mode -1)
    (goto-char (point-min))
    (flush-lines "TAGS\\(<[0-9]+>\\)?")
    (when prefs-suppress-snaffle-database-p
      (goto-char (point-min))
      (flush-lines "dlisp/d-snaffle.*\\.el") ;; PUT BACK!
      )
    (goto-char (point-min))
    (flush-lines " \\*d-[0-9]*\\*")
    (goto-char (point-min))
    (d-quote
     (re-search-forward (if emacs-dialect-xemacs-p
                           (concat "^....\"?" (regexp-quote d-electric--buffer-to-choose) "\"?\\s-") ;; varsity fix
                         (concat "^...." (regexp-quote d-electric--buffer-to-choose) "  "))
     nil
     t))
    (beginning-of-line)
    ;;(forward-line 2)
    ;;(insert "KKK")
    (read-only-mode 1)
    ;;(execute-kbd-macro "\C-n")
    (setq d-electric--foo t)
    ))

(setq d-electric--foo nil)

(defadvice electric-buffer-update-highlight (around d-speedbar-downdown activate)
  (when d-electric--foo
    (forward-line 1)
    (setq d-electric--foo nil))
  ad-do-it
  )

(add-hook 'electric-buffer-menu-mode-hook 'd-electric-hook)

(if emacs-dialect-xemacs-p
    (progn
      ;; patch for stupid bug
      (save-window-excursion
        (safe-command (execute-kbd-macro [insert]) 'QUIET))
      ))

(defun d-Electric-buffer-menu-select (&rest args)
  "This function is very clever"
  (interactive "P")
  (unwind-protect
      (progn
        (d-quote let (str)
          (assert (eq major-mode 'electric-buffer-menu-mode))
          (setq str (d-get-filename))
          (if (= (aref str 0) ?*)
              (switch-to-buffer str)
            (d-find-file str)))
        (call-interactively 'Electric-buffer-menu-select)
        )
    (setq d-old-method nil)
    (if (fboundp 'd-speedbar) (run-with-timer 0.01 nil 'd-speedbar))
    ))

(when prefs-davins-keybindings-online-p
  (global-set-key [f5] 'd-get-filename)
  )

(defun d-get-filename ()
  "Gets the filename on the RHS of the electric-buffer-menu-mode
screen or else *foo* on the LHS"
  (interactive)
  (let ((line (d-current-line-as-string)))
    (cond
     ((string-match "  \\(/[-a-zA-Z0-9/_. ]*$\\)" line)
      (setq line (substring line (match-beginning 1) (match-end 1))))
     ((string-match "  \\(\\(~/[a-zA-Z0-9]*\\)/[-a-zA-Z0-9/_. ]*$\\)" line)
      (setq line (substring line (match-beginning 1) (match-end 1))))
     ((string-match "  \\([a-zA-Z]:/[-a-zA-Z0-9/_. ]*$\\)" line)
      (setq line (substring line (match-beginning 1) (match-end 1))))
     ((string-match "^....\\(\\*[-a-zA-Z0-9_]+\\*\\)" line)
      (setq line (substring line (match-beginning 1) (match-end 1))))
     (t
      (d-beeps "t")
      ))
    line))

(when prefs-davins-keybindings-online-p
  (global-set-key [f5] 'd-major-mode)
  )

(defun d-major-mode ()
  (interactive)
  (message "major-mode=%s" major-mode)
  ;;(message "current-line=%s" (d-current-line-as-string))
  )

(provide 'd-electric)
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:57:00 NZST 2019
Best viewed at 800x600 or above resolution.
© Copyright 1999-2019 Davin Pearson.
Please report any broken links to