From: szymon
Subject: Critique my code.
Date: 
Message-ID: <87vfiqzoj2.fsf@darkstar.example.net>
;;; This dot-file is under construction. I'm new emacs&lisp user - please
;;; critique this code.  To see some, ehem, "real" code go to "set custom
;;; keys" section (line 88).


(require 'cl)

((lambda (lp-lst) (setq load-path (append (mapcar #'expand-file-name lp-lst) load-path)))
 '("~/site/slime" "/opt/emacs-stuff" "~/site/gnus-5.10.6/lisp" "~/site"
   "~/site/w3m-emacs/share/emacs/site-lisp/w3m" "~/site/elib-1.0"))

((lambda (lp-lst)
   (setq Info-default-directory-list
	 (append (mapcar #'expand-file-name lp-lst) Info-default-directory-list)))
 '("~/site/gnus-5.10.6/texi" "~/site/w3m-emacs/info" "~/bigloo" "~/site/elib-1.0"))

(mapc #'require '(w3m-load info swbuff rx smtpmail gnus-load slime info-apropos))

(setq-default default-frame-alist '((vertical-scroll-bars . nil)
				    (tool-bar-lines . 0)
				    (menu-bar-lines . 0)
				    (font . "10x20")
				    (background-color . "black")
				    (foreground-color . "PaleGreen")
	                            (cursor-color . "PaleGreen")))

(setq-default line-number-mode    t
	      column-number-mode  t)

(setq sbcl-pa                             "/opt/sbcl/bin/sbcl"
      cmucl-pa                            "/opt/cmucl/bin/lisp"
      clisp-pa                            "/usr/bin/clisp -K full -m 128MB"
      common-lisp-hyperspec-root          "file:///usr/doc/LISP/HyperSpec/"
      max-lisp-eval-depth                 2000
      max-specpdl-size                    2000
      inhibit-startup-message             t
      mouse-wheel-mode                    t
      kill-read-only-ok                   t
      inferior-lisp-program               cmucl-pa
      initial-major-mode                  'ielm
      gnus-inhibit-startup-message        t)

;;; misc. func.
;; 1 (from emacswiki)
(defun eshell/clear () (interactive) (let ((inhibit-read-only t)) (delete-region (point-min) (point-max))))
;; 2 (from emacswiki)
(defun ssb-match-paren (arg)
  "Go to the matching parenthesis if on parenthesis otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))
;; 3
(defun ssb-ens-lst (list?) (if (listp list?) list? (list list?)))
;;; end mfunc.

(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))

(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

;;; ----------------------------------------------------------- [ www browser ]

(autoload 'w3m "w3m" "Interface for w3m on Emacs." t)
(autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t) 
(setq w3m-command "/usr/local/bin/w3m"
      w3m-home-page "file:///usr/doc/LISP/HyperSpec/Front/index.htm"
      browse-url-browser-function 'w3m-browse-url)

;;; ---------------------------------------------------------------------------

;;; ------------------------------------------------------- [ unset some keys ]

(global-unset-key [(control z)])
(global-unset-key [(control x) (control c)])

;;; ---------------------------------------------------------------------------

;;; ------------------------------------------------------- [ set custom keys ]
;; by me :) do not laugh i'm not programmer nor geek.
;; I'm (still :-( -- have no time) clisp/elisp newbie, so please be polite..

(defun ssb-make-cdll (symb initial%list)
  (let ((initial-list (ssb-ens-lst initial%list)))
    (put symb (quote number-of-nodes) (length initial-list))
    (set symb (loop for i in initial-list
		    with b = (acons nil nil (car initial-list))
		    for l = b then (setf (cdar l) (acons l nil i))
		    finally (return (setf (caar b) l (cdar l) b))))))

(defmacro ssb-make-select-key (key name %hook mode%name else-command)

  (let ((cdll (intern (concat "ssb-" name "-cdll")))
	(dll-to-lst-name (intern (concat "ssb-" name "-cdll-to-list")))
	(hook-list (ssb-ens-lst %hook))
	(mode-name-list (ssb-ens-lst mode%name)))

    `(progn
       
       (fset (quote ,dll-to-lst-name)   ; for example:
	     (function (lambda nil      ;  (mapc 'kill-buffer (ssb-info-cdll-to-list))
			 (if ,cdll      ; kills all info buffers.
			  (loop repeat (get (quote ,cdll) 'number-of-nodes)
				for i = ,cdll then (cdar i)
				collect (cdr i))))))
       (defvar ,cdll nil)

       ,@(loop for i in hook-list collect
	       `(add-hook
		 (quote ,i)
		 (function
		  (lambda ()
		    (setq ,cdll
			  (if ,cdll
			      (let* ((next (cdar ,cdll)) (nod (acons ,cdll next (current-buffer))))
				(incf (get (quote ,cdll) 'number-of-nodes))
				(setf (cdar ,cdll) nod (caar next) nod))
			    (ssb-make-cdll (quote ,cdll) (current-buffer))))))))

       (add-hook 'kill-buffer-hook
		 (function
		  (lambda ()
		    (symbol-macrolet
			((del!current!node
			  (unless (zerop (decf (get (quote ,cdll) 'number-of-nodes)))
			    (prog1 (caar ,cdll)
			      (setf (cdar (caar ,cdll)) (cdar ,cdll)
				    (caar (cdar ,cdll)) (caar ,cdll)
				    ,cdll nil)))))
		      (when (and (memq major-mode (quote ,mode-name-list)) ,cdll)
			(if (eq (cdr ,cdll) (current-buffer))
			    (switch-to-buffer
			     (if (and (setq ,cdll del!current!node)
				      (memq (prog2
					      (switch-to-buffer (other-buffer))
					      major-mode
					    (switch-to-buffer (other-buffer)))
					  (quote ,mode-name-list)))
				 (cdr ,cdll)
			       (other-buffer)))
			  (setq ,cdll
				(prog1 ,cdll
				  (while (not (eq (cdr (setq ,cdll (cdar ,cdll))) (current-buffer))))
				  del!current!node))))))))

       (global-set-key (kbd ,key) (function
				   (lambda () (interactive)
				     (if ,cdll
					 (switch-to-buffer
					  (cdr
					   (if (memq major-mode (quote ,mode-name-list))
					       (setq ,cdll (caar ,cdll))
					     ,cdll))))
				     ,(if else-command
					  `(unless ,cdll (,else-command)))))))))


;;; ------------------------------------------------------------------------------------------
;; There is annoying problem with `byte-compile-file' function - it
;; mess with `ssb-LISP-cdll' (circular, double linked) list. It
;; (`byte-compile-..') do not run `kill-buffer-hook' functions. I have
;; not idea how to fix this (please help). There is function which
;; clean mess caused by `byte-compile-file':

(defun rebulid-ssb-LISP-cdll nil ; remove killed buffers created by `byte-compile-file'
 (ssb-make-cdll 'ssb-LISP-cdll
		(remove-if #'(lambda (x) (eq (buffer-name x) nil))
			   (ssb-LISP-cdll-to-list))))

;; I got strange warnig (after byte compilation this file):
;;     In rebulid-ssb-LISP-cdll:
;;     .emacs:162:84:Warning: Function `remove-if' from cl package called at runtime
;;; ------------------------------------------------------------------------------------------


;; --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
;;                      key    ssb-x-cddl      hook-name          mode-name       command  
;; --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
(ssb-make-select-key   "s-i"     "info"      Info-mode-hook       Info-mode        info)  
(ssb-make-select-key   "s-w"     "w3m"       w3m-mode-hook        w3m-mode         w3m)  
(ssb-make-select-key   "s-s"     "eshell"    eshell-mode-hook     eshell-mode      eshell)

(ssb-make-select-key "s-;"
                     "slime/ielm"
                     (slime-repl-mode-hook ielm-mode-hook)
                     (slime-repl-mode inferior-emacs-lisp-mode)
                     nil)

(ssb-make-select-key "s-l"
                     "LISP"
                     (lisp-mode-hook emacs-lisp-mode-hook)
                     (emacs-lisp-mode lisp-mode)
                     nil)

;; --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

(defvar *last-buffers* nil)

(macrolet

    ((get-first-matching-buffer
      (buffers regex)
      `(if ,buffers
	   (loop for i in ,buffers
		 if (and (not (string-match (rx (or " *Minibuf-0*" " *Minibuf-1*")) (buffer-name i)))
			 (string-match ,regex (buffer-name i)))
		 do (return i))))

     (cycle
      (regex lacking?)
      `(lambda () (interactive)
	 (let ((buff (get-first-matching-buffer (cdr (buffer-list)) (rx ,regex))))
	   (if buff
	       (progn (push buff *last-buffers*) (switch-to-buffer buff))
	     ,lacking?))))

     (set-keys
      (&rest lst)
      `(progn ,@(loop for (f r) in lst collect
		      `(global-set-key
			(kbd ,f)
			,(cond ((functionp r) `(function ,r)) ((keymapp r) `(quote ,r)) (t r)))))))

  (set-keys

   ("s-p"         swbuff-switch-to-previous-buffer)
   ("s-n"         swbuff-switch-to-next-buffer)
   ("%"           ssb-match-paren)
   ("C-;"         undo)
   ("C-."         repeat)
   ("H-v"         quoted-insert)
   ("C-<return>"  newline)
   ("s-h"         help-command)
   ("C-h"         delete-backward-char)
   ("H-h"         backward-kill-word)
   ("H-b"         buffer-menu-other-window)
   ("s-b"         (lambda () (interactive) (buffer-menu-other-window t)))
   ("s-o"         (lambda () (interactive)
		    (if (cdr *last-buffers*)
			(progn (switch-to-buffer (cadr *last-buffers*))
			       (setq *last-buffers* nil))
		      (switch-to-buffer (other-buffer (current-buffer) t)))))

;;; absoleted: (see `ssb-make-select-key')
;;  ("s-s" (cycle "*eshell*" nil))
;;  ("s-l" (cycle (or ".lisp" ".lsp" ".l" ".el" ".emacs") nil))
;;  ("s-w" (cycle (or (group line-start "*w3m*" line-end) (group line-start "*w3m*<" (in "1-9") ">" line-end)) nil))
;;  ("s-;" (cycle (group "*slime-repl[" (in "1-9") "]*") nil))

   ("s-t"         (cycle (or ".txt" ".text" "README" "INSTALL") nil))))

(define-key slime-mode-map [(hyper j)] 'slime-eval-defun)

;;; ---------------------------------------------------------------------------
;;; end.


regards, Szymon.

From: Barry Margolin
Subject: Re: Critique my code.
Date: 
Message-ID: <barmar-69D7C7.22240920052004@comcast.dca.giganews.com>
In article <··············@darkstar.example.net>, szymon <···@wp.pl> 
wrote:

> ;;; This dot-file is under construction. I'm new emacs&lisp user - please
> ;;; critique this code.  To see some, ehem, "real" code go to "set custom
> ;;; keys" section (line 88).

You should probably post this in an Emacs newsgroup.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: szymon
Subject: Re: Critique my code.
Date: 
Message-ID: <87brkick1s.fsf@darkstar.example.net>
Barry Margolin <······@alum.mit.edu> writes:

> You should probably post this in an Emacs newsgroup.
ok.
Should I remove this from c.l.l?

regards.