;;================================
;; this is .emacs
;;================================
(setq load-path (cons (expand-file-name "~/.emacs.d/") load-path))
(require 'etheme)
(global-set-key "/M-g" 'goto-line)
(global-set-key "/M-s" 'find-tag)
(setq frame-title-format "%S: %f")
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(c-basic-offset 4)
'(case-fold-search t)
'(current-language-environment "UTF-8")
'(default-input-method "rfc1345")
'(tool-bar-mode)
'(column-number-mode)
'(global-font-lock-mode t nil (font-lock)))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
;;============================
;; this is .emacs.d/etheme.el
;;============================
;;; etheme.el --- Theme support in emacs
;;;
;;; Copyright (C) 2005 Seong-Kook Shin <cinsky@gmail.com>
;;;
;;; 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 2 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 details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;;
;;;
;;; $Id: etheme.el,v 1.5 2005/06/24 23:59:40 cinsk Exp $
;;;
(eval-when-compile
(require 'cl))
(defgroup etheme nil
"Provide alternative theme-style face color configuration"
:version "22.0"
:group 'Faces)
(defvar etheme-current-theme
nil
"Current theme name")
(defvar etheme-set-theme-hook
nil
"Hook function called before applying any theme.")
(defvar etheme-alist
'(("cinsk" 1)
("vim" 2)
("elflord" 3)
("morning" 4)
("canyon" 5)
("blue" 6)
("darkblue" 7)
("desert" 8)
)
"Installed etheme name alist")
;;;
;;; Default values of White on Black
;;;
;;; modeline black on grey75
;;; modeline-inactive grey80 on grey30
;;; isearch brown4 on palevioletred2
;;; font-lock-comment-face chocolate1 on unspecified
;;; font-lock-constant-face Aquamarine on unspecified
;;; font-lock-type-face PaleGreen on unspecified
;;; font-lock-variable-name-face LightGoldenrod on unspecified
;;; font-lock-function-name-face LightSkyBlue on unspecified
;;; font-lock-preprocessor-face unspecified on unspecified
;;; font-lock-string-face LightSalmon on unspecified
;;; font-lock-keyword-face Cyan1 on unspecified
;;;
;;;
;;; Default values of Black on White
;;;
;;; modeline black on grey75
;;; modeline-inactive grey20 on grey90
;;; isearch lightskyblue1 on magenta2
;;; font-lock-comment-face firebrick on unspecified
;;; font-lock-constant-face CadetBlue on unspecified
;;; font-lock-type-face ForestGreen on unspecified
;;; font-lock-variable-name-face DarkGoldenrod on unspecified
;;; font-lock-function-name-face Blue1 on unspecified
;;; font-lock-preprocessor-face unspecified on unspecified
;;; font-lock-string-face RosyBrown on unspecified
;;; font-lock-keyword-face Purple on unspecified
;;;
;;;
;;; DO NOT SET ANY ATTRIBUTE ON THESE FACES.
;;;
;;; font-lock-comment-delimiter-face unspecified on unspecified
;;; font-lock-doc-face unspecified on unspecified
;;; font-lock-negation-char-face unspecified on unspecified
;;; font-lock-regexp-backslash unspecified on unspecified
;;; font-lock-regexp-backslash-construct unspecified on unspecified
;;; font-lock-warning-face Red1 on unspecified
(defvar etheme-saved-face-list
'(modeline
modeline-inactive
isearch
font-lock-builtin-face
font-lock-comment-face
font-lock-constant-face
font-lock-type-face
font-lock-variable-name-face
font-lock-function-name-face
font-lock-preprocessor-face
font-lock-string-face
font-lock-keyword-face)
"List of face names which will be stored between theme change."
)
(defvar etheme-cinsk-faces
'((default :foreground "powder blue" :background "black")
(modeline :foreground "white" :background "IndianRed4")
(modeline-inactive :foreground "grey80" :background "gray30")
(isearch :foreground "brown4" :background "palevioletred2")
;; (font-lock-builtin-face :foreground "DarkGoldenrod4")
(font-lock-comment-face :foreground "chocolate1")
(font-lock-constant-face :foreground "Aquamarine")
(font-lock-type-face :foreground "PaleGreen")
(font-lock-variable-name-face :foreground "LightGoldenrod")
(font-lock-function-name-face :foreground "LightSkyBlue")
(font-lock-preprocessor-face :foreground unspecified)
(font-lock-string-face :foreground "LightSalmon")
(font-lock-keyword-face :foreground "Cyan1"))
"cinsk style face attribute set")
(defvar etheme-cinsk-hook
nil
"Hook for cinsk theme")
(defvar etheme-canyon-faces
'((default :foreground "grey30" :background "NavajoWhite2")
(modeline :foreground "grey90" :background "chocolate2")
(modeline-inactive :foreground "grey80" :background "chocolate4")
(isearch :foreground "brown4" :background "palevioletred2")
(font-lock-builtin-face :foreground "DarkGoldenrod4")
(font-lock-comment-face :foreground "Firebrick")
(font-lock-constant-face :foreground "purple4")
(font-lock-type-face :foreground "aquamarine4")
(font-lock-variable-name-face :foreground "cyan4")
(font-lock-function-name-face :foreground "green4")
(font-lock-preprocessor-face :foreground "IndianRed3")
(font-lock-string-face :foreground "HotPink4")
(font-lock-keyword-face :foreground "DarkOrange4")))
(defvar etheme-canyon-hook
nil
"Hook for canyon theme")
(defvar etheme-vim-faces
'((default :foreground "gray" :background "black")
(modeline :foreground "black" :background "gray75")
(modeline-inactive :foreground "grey80" :background "gray30")
(isearch :foreground "brown4" :background "palevioletred2")
;; (font-lock-builtin-face :foreground "DarkGoldenrod4")
(font-lock-comment-face :foreground "RoyalBlue")
(font-lock-constant-face :foreground "Aquamarine")
(font-lock-type-face :foreground "green")
(font-lock-variable-name-face :foreground "LightGoldenrod")
(font-lock-function-name-face :foreground "LightSkyBlue")
(font-lock-preprocessor-face :foreground "magenta")
(font-lock-string-face :foreground "red")
(font-lock-keyword-face :foreground "DarkOrange2"))
"graphical version of vim style face attribute set")
(defvar etheme-vim-hook
nil
"Hook for vim theme")
(defvar etheme-elflord-faces
'((default :foreground "cyan" :background "black")
(modeline :foreground "black" :background "gray75")
(modeline-inactive :foreground "grey80" :background "gray30")
(isearch :foreground "brown4" :background "palevioletred2")
;; (font-lock-builtin-face :foreground "DarkGoldenrod4")
(font-lock-comment-face :foreground "#80a0ff")
(font-lock-constant-face :foreground "magenta")
(font-lock-type-face :foreground "#60ff60")
(font-lock-variable-name-face :foreground "#40ffff")
(font-lock-function-name-face :foreground "white")
(font-lock-preprocessor-face :foreground "#ff80ff")
(font-lock-string-face :foreground "magenta")
(font-lock-keyword-face :foreground "#aa4444"))
"vim elflord-like face attribute set")
(defvar etheme-elflord-hook
nil
"Hook for elflord theme")
(defvar etheme-morning-faces
'((default :foreground "black" :background "grey90")
(modeline :foreground unspecified :background "LightBlue1")
(modeline-inactive :foreground unspecified :background "LightBlue3")
(isearch :foreground unspecified :background "yellow")
;; (font-lock-builtin-face :foreground "DarkGoldenrod4")
(font-lock-comment-face :foreground "blue")
(font-lock-constant-face :foreground "magenta")
(font-lock-type-face :foreground "forest green")
(font-lock-variable-name-face :foreground "blue4")
(font-lock-function-name-face :foreground "sienna4")
(font-lock-preprocessor-face :foreground "DarkViolet")
(font-lock-string-face :foreground "magenta")
(font-lock-keyword-face :foreground "SlateBlue"))
"vim morning-like face attribute set")
(defvar etheme-morning-hook
nil
"Hook for morning theme")
(defvar etheme-blue-faces
'((default :foreground "white" :background "navy")
(modeline :foreground "black" :background "deep sky blue")
(modeline-inactive :foreground "grey60" :background "navy")
(isearch :foreground unspecified :background "yellow")
(font-lock-builtin-face :foreground "yellow")
(font-lock-comment-face :foreground "LightGrey")
(font-lock-constant-face :foreground "cyan")
(font-lock-type-face :foreground "yellow")
(font-lock-variable-name-face :foreground "burlywood")
(font-lock-function-name-face :foreground "beige")
(font-lock-preprocessor-face :foreground "green")
(font-lock-string-face :foreground "cyan")
(font-lock-keyword-face :foreground "tomato"))
"vim morning-like face attribute set")
(defvar etheme-blue-hook
nil
"Hook for blue theme")
(defvar etheme-darkblue-faces
'((default :foreground "LightGrey" :background "#000040")
(modeline :foreground "black" :background "deep sky blue")
(modeline-inactive :foreground "grey60" :background "navy")
(isearch :foreground unspecified :background "yellow")
(font-lock-builtin-face :foreground "yellow")
(font-lock-comment-face :foreground "#80a0ff")
(font-lock-constant-face :foreground "cyan")
(font-lock-type-face :foreground "#60ff60")
(font-lock-variable-name-face :foreground "#40ffff")
(font-lock-function-name-face :foreground "beige")
(font-lock-preprocessor-face :foreground "#ff80ff")
(font-lock-string-face :foreground "#ffa0a0")
(font-lock-keyword-face :foreground "green"))
"vim morning-like face attribute set")
(defvar etheme-darkblue-hook
nil
"Hook for darkblue theme")
(defvar etheme-desert-faces
'((default :foreground "white" :background "grey20")
(modeline :foreground "black" :background "deep sky blue")
(modeline-inactive :foreground "grey20" :background "#c2bfa5")
(isearch :foreground "slategrey" :background "khaki")
(font-lock-builtin-face :foreground "yellow")
(font-lock-comment-face :foreground "SkyBlue")
(font-lock-constant-face :foreground "#ffa0a0")
(font-lock-type-face :foreground "darkkhaki")
(font-lock-variable-name-face :foreground "palegreen")
(font-lock-function-name-face :foreground "beige")
(font-lock-preprocessor-face :foreground "indianred")
(font-lock-string-face :foreground "#ffa0a0")
(font-lock-keyword-face :foreground "navajowhite"))
"vim morning-like face attribute set")
(defvar etheme-desert-hook
nil
"Hook for darkblue theme")
(defun etheme-set-faces (theme)
"Set the given face attribute set THEME"
(mapcar #'(lambda (arg)
(apply #'set-face-attribute
(append (list (car arg) nil) (cdr arg))))
theme))
(defun etheme-run-hook (theme-name)
"Run THEME-NAME hook"
(let ((hook-name (intern (concat "etheme-" theme-name "-hook"))))
(run-hooks hook-name)))
(defun etheme-add-hook (theme-name function &optional append)
"Add FUNCTION to the THEME-NAME hook"
(let ((hook-name (intern (concat "etheme-" theme-name "-hook"))))
(add-hook hook-name function append)))
(defun etheme-apply-theme (theme-name)
"Set the current theme to THEME-NAME"
(if (stringp theme-name)
(let ((faces (eval (intern (concat "etheme-" theme-name "-faces")))))
(setq etheme-current-theme theme-name)
(etheme-run-hook theme-name)
(etheme-set-faces faces)
)))
(defun etheme-set-theme (theme-name)
"Set the current theme to THEME-NAME"
(interactive "P")
(global-font-lock-mode 1)
(let ((name theme-name))
(if (stringp name)
(etheme-apply-theme name)
(progn (etheme-apply-theme
(setq name (completing-read "theme name: "
etheme-alist nil t "")))
(message "etheme: %s selected" name)))))
(etheme-add-hook "vim" 'menu-bar-right-scroll-bar)
(etheme-add-hook "vim" '(lambda () (tool-bar-mode 1)))
(etheme-add-hook "vim" '(lambda () (set-cursor-color "white")))
(etheme-add-hook "vim" '(lambda () (set-mouse-color "white")))
(etheme-add-hook "morning" 'menu-bar-right-scroll-bar)
(etheme-add-hook "morning" '(lambda () (tool-bar-mode 1)))
(etheme-add-hook "morning" '(lambda () (set-cursor-color "plum4")))
(etheme-add-hook "morning" '(lambda () (set-mouse-color "blue4")))
(etheme-add-hook "elflord" 'menu-bar-right-scroll-bar)
(etheme-add-hook "elflord" '(lambda () (tool-bar-mode 1)))
(etheme-add-hook "elflord" '(lambda () (set-cursor-color "white")))
(etheme-add-hook "elflord" '(lambda () (set-mouse-color "white")))
(etheme-add-hook "cinsk" 'menu-bar-left-scroll-bar)
(etheme-add-hook "cinsk" '(lambda () (tool-bar-mode -1)))
(etheme-add-hook "cinsk" '(lambda () (set-cursor-color "white")))
(etheme-add-hook "cinsk" '(lambda () (set-mouse-color "white")))
(etheme-add-hook "canyon" 'menu-bar-left-scroll-bar)
(etheme-add-hook "canyon" '(lambda () (tool-bar-mode 1)))
(etheme-add-hook "canyon" '(lambda () (set-cursor-color "plum4")))
(etheme-add-hook "canyon" '(lambda () (set-mouse-color "blue4")))
(etheme-add-hook "blue" 'menu-bar-right-scroll-bar)
(etheme-add-hook "blue" '(lambda () (tool-bar-mode -1)))
(etheme-add-hook "blue" '(lambda () (set-cursor-color "SkyBlue")))
(etheme-add-hook "blue" '(lambda () (set-mouse-color "DimGray")))
(etheme-add-hook "darkblue" 'menu-bar-right-scroll-bar)
(etheme-add-hook "darkblue" '(lambda () (tool-bar-mode -1)))
(etheme-add-hook "darkblue" '(lambda () (set-cursor-color "white")))
(etheme-add-hook "darkblue" '(lambda () (set-mouse-color "yellow")))
(etheme-add-hook "desert" 'menu-bar-right-scroll-bar)
(etheme-add-hook "desert" '(lambda () (tool-bar-mode -1)))
(etheme-add-hook "desert" '(lambda () (set-cursor-color "khaki")))
(etheme-add-hook "desert" '(lambda () (set-mouse-color "yellow")))
(provide 'etheme)
;;==========================
;; this is .emacs.d/setnu.el
;;==========================
;;; vi-style line number mode for Emacs
;;; (requires Emacs 19.29 or later, or XEmacs 19.14 or later)
;;; Copyright (C) 1994, 1995, 1997 Kyle E. Jones
;;;
;;; 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 2, 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 details.
;;;
;;; A copy of the GNU General Public License can be obtained from this
;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
;;; 02139, USA.
;;;
;;; Send bug reports to kyle@wonderworks.com
;;
;; M-x setnu-mode toggles the line number mode on and off.
;;
;; turn-on-setnu-mode is useful for adding to a major-mode hook
;; variable.
;; Example:
;; (add-hook 'text-mode-hook 'turn-on-setnu-mode)
;; to automatically turn on line numbering when enterting text-mode."
(provide 'setnu)
(defconst setnu-running-under-xemacs
(or (string-match "XEmacs" emacs-version)
(string-match "Lucid" emacs-version)))
(defconst setnu-mode-version "1.06"
"Version number for this release of setnu-mode.")
(defvar setnu-mode nil
"Non-nil if setnu-mode is active in the current buffer.")
(make-variable-buffer-local 'setnu-mode)
(defvar setnu-start-extent nil
"First extent of a chain of extents used by setnu-mode.
Each line has its own extent. Each line extent has a
`setnu-next-extent' property that points to the next extent in
the chain, which is the extent for the next line in the buffer.
There is also a `setnu-prev-extent' that points at the previous
extent in the chain. To distinguish them from other extents the
setnu-mode extents all have a non-nil `setnu' property.")
(make-variable-buffer-local 'setnu-start-extent)
(defvar setnu-glyph-obarray (make-vector 401 0)
"Obarray of symbols whose values are line number glyphs.
Each symbol name is the string represnetation of a number, perhaps
passed with spaces. The value of the symbol is a glyph that can
be made the begin glyph of an extent to display as a line number.")
(defvar setnu-begin-glyph-property (if (fboundp 'extent-property)
'begin-glyph
'before-string)
"Property name to use to set the begin glyph of an extent.")
(defvar setnu-line-number-format (if setnu-running-under-xemacs "%4d" "%6d ")
"String suitable for `format' that will generate a line number string.
`format' will be called with this string and one other argument
which will be an integer, the line number.")
(defvar setnu-line-number-face 'bold
"*Face used to display the line numbers.
Currently this works for XEmacs 19.12 and later versions only.")
(defun setnu-mode (&optional arg)
"Toggle setnu-mode.
With prefix argument, turn setnu-mode on if argument is positive.
When setnu-mode is enabled, a line number will appear at the left
margin of each line."
(interactive "P")
(let ((oldmode (not (not setnu-mode)))
(inhibit-quit t))
(setq setnu-mode (or (and arg (> (prefix-numeric-value arg) 0))
(and (null arg) (null setnu-mode))))
(if (not (eq oldmode setnu-mode))
(if setnu-mode
(setnu-mode-on)
(setnu-mode-off)))))
(defun turn-on-setnu-mode ()
"Turn on setnu-mode.
Useful for adding to a major-mode hook variable.
Example:
(add-hook 'text-mode-hook 'turn-on-setnu-mode)
to automatically turn on line numbering when enterting text-mode."
(setnu-mode 1))
;;; Internal functions
;;; The program is written using XEmacs terminology,
;;; e.g. extents, glyphs, etc. Functions are defined to twist
;;; the FSF Emacs overlay API into the XEmacs model.
(defconst setnu-running-under-xemacs
(or (string-match "XEmacs" emacs-version)
(string-match "Lucid" emacs-version)))
(if setnu-running-under-xemacs
(fset 'setnu-make-extent 'make-extent)
(fset 'setnu-make-extent 'make-overlay))
(if setnu-running-under-xemacs
(fset 'setnu-delete-extent 'delete-extent)
(fset 'setnu-delete-extent 'delete-overlay))
(if setnu-running-under-xemacs
(fset 'setnu-extent-property 'extent-property)
(fset 'setnu-extent-property 'overlay-get))
(if setnu-running-under-xemacs
(fset 'setnu-set-extent-property 'set-extent-property)
(fset 'setnu-set-extent-property 'overlay-put))
(if setnu-running-under-xemacs
(fset 'setnu-set-extent-endpoints 'set-extent-endpoints)
(fset 'setnu-set-extent-endpoints 'move-overlay))
(if setnu-running-under-xemacs
(fset 'setnu-extent-end-position 'extent-end-position)
(fset 'setnu-extent-end-position 'overlay-end))
(if setnu-running-under-xemacs
(fset 'setnu-extent-start-position 'extent-start-position)
(fset 'setnu-extent-start-position 'overlay-start))
(if setnu-running-under-xemacs
(defun setnu-set-extent-begin-glyph (e g)
(set-extent-begin-glyph e g 'outside-margin))
(defun setnu-set-extent-begin-glyph (e g)
(overlay-put e setnu-begin-glyph-property g)))
(fset 'setnu-make-glyph (if setnu-running-under-xemacs 'make-glyph 'identity))
(cond ((and setnu-running-under-xemacs (fboundp 'set-glyph-face))
(fset 'setnu-set-glyph-face 'set-glyph-face))
(setnu-running-under-xemacs
(fset 'setnu-set-glyph-face 'ignore))
(t ; FSF Emacs
(defun setnu-set-glyph-face (g face)
(put-text-property 0 (length g) 'face face g))))
(defun setnu-mode-off ()
"Internal shutdown of setnu-mode.
Deletes the extents associated with setnu-mode."
(if (and setnu-running-under-xemacs
(fboundp 'remove-specifier))
(remove-specifier left-margin-width (current-buffer)))
(if setnu-start-extent
(let (e ee)
(setq e setnu-start-extent)
(while e
(setq ee e)
(setq e (setnu-extent-property e 'setnu-next-extent))
(setnu-delete-extent ee))
(setq setnu-start-extent nil))))
(defun setnu-mode-on ()
"Internal startup of setnu-mode.
Sets up the extents associated with setnu-mode."
(if (and setnu-running-under-xemacs
(fboundp 'set-specifier))
(set-specifier left-margin-width 6 (current-buffer)))
(let ((done nil)
(curr-e nil)
(n 1)
(match-data (match-data))
e start numstr)
(unwind-protect
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(setq start (point))
(while (not done)
(setq done (null (search-forward "/n" nil 0)))
(setq e (setnu-make-setnu-extent start (point)))
(if (null setnu-start-extent)
(setq setnu-start-extent e
curr-e e)
(setnu-set-extent-property curr-e 'setnu-next-extent e)
(setnu-set-extent-property e 'setnu-prev-extent curr-e)
(setq curr-e e))
(setq numstr (format setnu-line-number-format n))
(setnu-set-extent-property e 'line-number numstr)
(setnu-set-extent-begin-glyph e (setnu-number-glyph numstr))
(setq n (1+ n)
start (point)))))
(store-match-data match-data))))
(defun setnu-before-change-function (start end)
"Before change function for setnu-mode.
Notices when a delete is about to delete some lines and adjusts
the line number extents accordingly."
(if (or (not setnu-mode) (= start end))
() ;; not in setnu-mode or this is an insertion
(let ((inhibit-quit t)
(start-e nil)
(match-data (match-data))
end-e saved-next e ee)
(unwind-protect
(save-excursion
(save-restriction
(widen)
(goto-char start)
(if (search-forward "/n" end t)
(progn
(setq start-e (setnu-extent-at-create start nil)
saved-next (setnu-extent-property
start-e
'setnu-next-extent))
(setq end-e (setnu-extent-at-create end nil))
(setnu-set-extent-endpoints
start-e
(setnu-extent-start-position start-e)
(setnu-extent-end-position end-e))
(setnu-set-extent-property
start-e 'setnu-next-extent
(setnu-extent-property end-e 'setnu-next-extent))))
(if start-e
(progn
(setq e (setnu-extent-property start-e 'setnu-next-extent)
ee saved-next)
(while (and e (setnu-extent-property e 'setnu-next-extent))
(setq e (setnu-extent-property e 'setnu-next-extent)
ee (setnu-extent-property ee 'setnu-next-extent)))
(while (and e (not (eq ee start-e)))
(setnu-set-extent-begin-glyph
e (setnu-extent-property ee setnu-begin-glyph-property))
(setnu-set-extent-property
e 'line-number (setnu-extent-property ee 'line-number))
(setq e (setnu-extent-property e 'setnu-prev-extent)
ee (setnu-extent-property ee 'setnu-prev-extent)))
(setq end-e (setnu-extent-property start-e
'setnu-next-extent))
(and end-e
(setnu-set-extent-property end-e
'setnu-prev-extent
start-e))
(setq e saved-next)
(while (not (eq e end-e))
(setq ee e
e (setnu-extent-property e 'setnu-next-extent))
(setnu-delete-extent ee))))))
(store-match-data match-data)))))
(defun setnu-after-change-function (start end length)
"After change function for setnu-mode.
Notices when an insert has added some lines and adjusts
the line number extents accordingly."
(if (or (not setnu-mode) (= start end))
() ; not in setnu-mode or this is a deletion
(let ((inhibit-quit t)
(ee nil)
(match-data (match-data))
(new-lines 0)
start-e e saved-end saved-next n numstr)
(unwind-protect
(save-excursion
(save-restriction
(widen)
(setq start-e (setnu-extent-at-create start nil))
(if (< (setnu-extent-end-position start-e) (point))
;; bogus! insertion didn't put the text into
;; the extent because,
;; a. the extent was zero length or
;; b. this is FSF Emacs which means chars
;; inserted at the end position of an extent
;; are not inserted into the extent.
(setnu-set-extent-endpoints
start-e
(setnu-extent-start-position start-e)
end))
(setq saved-next (setnu-extent-property start-e
'setnu-next-extent)
saved-end (setnu-extent-end-position start-e)
e start-e)
(goto-char start)
(while (search-forward "/n" end 0)
(setnu-set-extent-endpoints e
(setnu-extent-start-position e)
(point))
(setq ee (setnu-make-setnu-extent (point) (point)))
(setnu-set-extent-property e 'setnu-next-extent ee)
(setnu-set-extent-property ee 'setnu-prev-extent e)
(setq e ee new-lines (1+ new-lines)))
(if ee
(progn
(setnu-set-extent-endpoints
e (setnu-extent-start-position e) saved-end)
(setnu-set-extent-property e 'setnu-next-extent saved-next)
(and saved-next
(setnu-set-extent-property
saved-next 'setnu-prev-extent e))
(setq e (setnu-extent-property start-e 'setnu-next-extent)
ee saved-next)
(while ee
(setnu-set-extent-begin-glyph
e (setnu-extent-property ee setnu-begin-glyph-property))
(setnu-set-extent-property
e 'line-number (setnu-extent-property ee 'line-number))
(setq e (setnu-extent-property e 'setnu-next-extent)
ee (setnu-extent-property ee 'setnu-next-extent)))
(setq n (1+ (string-to-int
(setnu-extent-property
(setnu-extent-property e 'setnu-prev-extent)
'line-number))))
(while e
(setq numstr (format setnu-line-number-format n))
(setnu-set-extent-property e 'line-number numstr)
(setnu-set-extent-begin-glyph
e (setnu-number-glyph numstr))
(setq e (setnu-extent-property e 'setnu-next-extent)
n (1+ n)))))))
(store-match-data match-data)))))
(defun setnu-number-glyph (number-string)
(let ((sym (intern number-string setnu-glyph-obarray)))
(if (boundp sym)
(symbol-value sym)
(let ((g (setnu-make-glyph number-string)))
(set sym g)
(setnu-set-glyph-face g setnu-line-number-face)
g ))))
(defun setnu-make-setnu-extent (beg end)
"Create an extent and set some properties that all setnu extents have."
(let ((e (setnu-make-extent beg end)))
(setnu-set-extent-property e 'setnu t)
;; (setnu-set-extent-property e 'begin-glyph-layout 'outside-margin)
(setnu-set-extent-property e 'detachable nil)
(setnu-set-extent-property e 'evaporate nil)
e ))
(cond ((fboundp 'overlays-in) ;; expect to see this in 19.30
(defun setnu-extent-at (pos buf)
"Finds the setnu extent at the position POS in the buffer BUF."
(catch 'done
(save-excursion
(and buf (set-buffer buf))
(let ((o-list (overlays-in pos (1+ pos))))
(while o-list
(if (overlay-get (car o-list) 'setnu)
(throw 'done (car o-list)))
(setq o-list (cdr o-list)))
nil )))))
((fboundp 'overlays-at)
(defun setnu-extent-at (pos buf)
"Finds the setnu extent at the position POS in the buffer BUF."
(catch 'done
(save-excursion
(and buf (set-buffer buf))
(let ((o-list (overlays-at pos)) o-lists)
;; search what overlays-at returns first. for all
;; but zero length extents this will return the
;; extent we want.
(while o-list
(if (overlay-get (car o-list) 'setnu)
(throw 'done (car o-list)))
(setq o-list (cdr o-list)))
;; No luck. Search the lists returned by
;; overlay-lists. Use overlays-recenter so we only
;; have to search the `before' lobe of the return
;; value.
(overlay-recenter (1- pos))
(setq o-lists (overlay-lists))
(setq o-list (cdr o-lists))
(while o-list
(if (and (overlay-get (car o-list) 'setnu)
(or (and (= pos (overlay-start (car o-list)))
(= pos (overlay-end (car o-list))))
(and (>= pos (overlay-start (car o-list)))
(< pos (overlay-end (car o-list))))))
(throw 'done (car o-list)))
(setq o-list (cdr o-list)))
nil )))))
((fboundp 'map-extents)
(defun setnu-extent-at (pos buf)
"Finds the setnu extent at the position POS in the buffer BUF."
(map-extents (function (lambda (e maparg)
(if (setnu-extent-property e 'setnu)
e
nil)))
buf pos pos)))
(t (error "can't find overlays-in, overlays-at, or map-extents!")))
(defun setnu-extent-at-create (pos buf)
"Like `setnu-extent-at' except if an extent isn't found, then
it is created based on where the extent failed to be found."
(let ((e (setnu-extent-at pos buf)) ee beg numstr)
(if e
e
;; no extent found so one must be created.
(save-excursion
(goto-char pos)
(beginning-of-line)
(setq e (setnu-extent-at (point) buf))
(cond (e
;; found one. extend it to cover this whole line.
;; this takes care of zero length extents that
;; might exist at bob or eob that can't be
;; inserted into.
(setq beg (point))
(forward-line 1)
(setnu-set-extent-endpoints e beg (point))
e )
((bobp)
;; we are at bob and there's no extent.
;;
;; this is because the extent that was there got
;; detached because all the text in the buffer was
;; deleted. so we create a new extent and make it
;; contain the whole buffer, since there can be no
;; other attached extents.
(setq e (setnu-make-setnu-extent (point-min) (point-max))
numstr (format setnu-line-number-format 1))
(setnu-set-extent-property e 'line-number numstr)
(setnu-set-extent-begin-glyph e (setnu-number-glyph numstr))
(setq setnu-start-extent e)
e )
(t
;; we must be at eob and there's no extent.
;;
;; this is because the extent that was there
;; shrank to zero length and was detached. create
;; a new extent that contains all text from point
;; to pos.
(setq e (setnu-make-setnu-extent (point) pos))
(setq ee (setnu-extent-at (1- (point)) buf))
(setnu-set-extent-property e 'setnu-prev-extent ee)
(setnu-set-extent-property ee 'setnu-next-extent e)
(setq numstr
(format setnu-line-number-format
(1+ (string-to-int
(setnu-extent-property ee 'line-number)))))
(setnu-set-extent-property e 'line-number numstr)
(setnu-set-extent-begin-glyph e (setnu-number-glyph numstr))
e ))))))
(add-hook 'before-change-functions 'setnu-before-change-function)
(add-hook 'after-change-functions 'setnu-after-change-function)