📄 line-num.el
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>EmacsWiki: line-num.el</title><link rel="alternate" type="application/wiki" title="Diese Seite bearbeiten" href="http://www.emacswiki.org/emacs-de?action=edit;id=line-num.el" /><link type="text/css" rel="stylesheet" href="/emacs/wiki.css" /><meta name="robots" content="INDEX,FOLLOW" /><link rel="alternate" type="application/rss+xml" title="EmacsWiki" href="http://www.emacswiki.org/emacs-de?action=rss" /><link rel="alternate" type="application/rss+xml" title="EmacsWiki: line-num.el" href="http://www.emacswiki.org/emacs-de?action=rss;rcidonly=line-num.el" /><link rel="alternate" type="application/rss+xml" title="Emacs Wiki with page content" href="http://www.emacswiki.org/emacs/full.rss" /><link rel="alternate" type="application/rss+xml" title="Emacs Wiki with page content and diff" href="http://www.emacswiki.org/emacs/full-diff.rss" /><link rel="alternate" type="application/rss+xml" title="Emacs Wiki including minor differences" href="http://www.emacswiki.org/emacs/minor-edits.rss" /><link rel="alternate" type="application/rss+xml" title="Changes for line-num.el only" href="http://www.emacswiki.org/emacs?action=rss;rcidonly=line-num.el" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body class="http://www.emacswiki.org/emacs-de"><div class="header"><a class="logo" href="http://www.emacswiki.org/emacs-de/%c3%9cbersicht"><img class="logo" src="/emacs_logo.png" alt="[Erste Seite]" /></a><span class="gotobar bar"><a class="local" href="http://www.emacswiki.org/emacs-de/%c3%9cbersicht">脺bersicht</a> <a class="local" href="http://www.emacswiki.org/emacs-de/Letzte_%c3%84nderungen">Letzte 脛nderungen</a> <a class="local" href="http://www.emacswiki.org/emacs-de/Neuigkeiten">Neuigkeiten</a> <a class="local" href="http://www.emacswiki.org/emacs-de/Suchen">Suchen</a> <a class="local" href="http://www.emacswiki.org/emacs-de/ElispSektion">ElispSektion</a> <a class="local" href="http://www.emacswiki.org/emacs-de/KurzAnleitung">KurzAnleitung</a> </span><!-- Google CSE Search Box Begins --><form class="tiny" action="http://www.google.com/cse" id="searchbox_004774160799092323420:6-ff2s0o6yi"><p><input type="hidden" name="cx" value="004774160799092323420:6-ff2s0o6yi" /><input type="text" name="q" size="25" /><input type="submit" name="sa" value="Search" /></p></form><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_004774160799092323420%3A6-ff2s0o6yi"></script><!-- Google CSE Search Box Ends --><h1><a title="Klicken um nach Verweisen auf diese Seite zu suchen" rel="nofollow" href="http://www.google.com/cse?cx=004774160799092323420:6-ff2s0o6yi&q=%22line-num.el%22">line-num.el</a></h1></div><div class="wrapper"><div class="content browse"><p><a href="http://www.emacswiki.org/emacs/download/line-num.el">Download</a></p><pre class="code"><span class="linecomment">;;; line-num.el --- Display line numbers in left-margin of buffer.</span><span class="linecomment">;;</span><span class="linecomment">;; Filename: line-num.el</span><span class="linecomment">;; Description: Display line numbers in left-margin of buffer.</span><span class="linecomment">;; Author: (Darryl Okahata) darrylo@hpsrdmo, Drew Adams</span><span class="linecomment">;; Maintainer: Drew Adams</span><span class="linecomment">;; Copyright (C) 1999-2009, Drew Adams, all rights reserved.</span><span class="linecomment">;; Copyright (C) 1989, Hewlett-Packard, all rights reserved.</span><span class="linecomment">;; Created: Wed Mar 31 16:18:24 1999</span><span class="linecomment">;; Version: 21.0</span><span class="linecomment">;; Last-Updated: Sat Dec 27 10:09:30 2008 (-0800)</span><span class="linecomment">;; By: dradams</span><span class="linecomment">;; Update #: 206</span><span class="linecomment">;; URL: http://www.emacswiki.org/cgi-bin/wiki/line-num.el</span><span class="linecomment">;; Keywords: local</span><span class="linecomment">;; Compatibility: GNU Emacs 20.x, GNU Emacs 21.x, GNU Emacs 22.x</span><span class="linecomment">;;</span><span class="linecomment">;; Features that might be required by this library:</span><span class="linecomment">;;</span><span class="linecomment">;; None</span><span class="linecomment">;;</span><span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><span class="linecomment">;;</span><span class="linecomment">;;; Commentary:</span><span class="linecomment">;;</span><span class="linecomment">;; Display line numbers in left-margin of buffer.</span><span class="linecomment">;;</span><span class="linecomment">;; New functions defined here:</span><span class="linecomment">;;</span><span class="linecomment">;; `display-line-numbers', `toggle-line-numbers-display',</span><span class="linecomment">;; `turn-on-line-numbers-display', `turn-off-line-numbers-display'.</span><span class="linecomment">;;</span><span class="linecomment">;; NOTE: `setnu.el' now provides similar, but generally better,</span><span class="linecomment">;; functionality.</span><span class="linecomment">;;</span><span class="linecomment">;; Original author was Darryl Okahata darrylo@hpsrdmo: The copy on</span><span class="linecomment">;; which the current (Adams) modifications were made was obtained from</span><span class="linecomment">;; Rick Kunin (rickk@sperdk).</span><span class="linecomment">;;</span><span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><span class="linecomment">;;</span><span class="linecomment">;;; Change log:</span><span class="linecomment">;;</span><span class="linecomment">;; 2004/11/26 dadams</span><span class="linecomment">;; Replaced decf with setq...1+.</span><span class="linecomment">;; turn-off-line-numbers-display: Error if not displaying line #s.</span><span class="linecomment">;; Removed calls to `fit-frame' (and require of fit-frame.el).</span><span class="linecomment">;; 2000/11/01 dadams</span><span class="linecomment">;; 1. Added: toggle-line-numbers-display, turn-on-line-numbers-display,</span><span class="linecomment">;; turn-off-line-numbers-display.</span><span class="linecomment">;; 2. Added global vars: displaying-line-numbers-p,</span><span class="linecomment">;; display-line-numbers-format-string, display-line-numbers-first-line,</span><span class="linecomment">;; display-line-numbers-count, display-line-numbers-buffer-name,</span><span class="linecomment">;; display-line-numbers-modified-p.</span><span class="linecomment">;; 1999/04/14 dadams</span><span class="linecomment">;; Commented out assignment to unused free var: insert-end.</span><span class="linecomment">;;</span><span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><span class="linecomment">;;</span><span class="linecomment">;; This program is free software; you can redistribute it and/or modify</span><span class="linecomment">;; it under the terms of the GNU General Public License as published by</span><span class="linecomment">;; the Free Software Foundation; either version 2, or (at your option)</span><span class="linecomment">;; any later version.</span><span class="linecomment">;; This program is distributed in the hope that it will be useful,</span><span class="linecomment">;; but WITHOUT ANY WARRANTY; without even the implied warranty of</span><span class="linecomment">;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span><span class="linecomment">;; GNU General Public License for more details.</span><span class="linecomment">;; You should have received a copy of the GNU General Public License</span><span class="linecomment">;; along with this program; see the file COPYING. If not, write to</span><span class="linecomment">;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth</span><span class="linecomment">;; Floor, Boston, MA 02110-1301, USA.</span><span class="linecomment">;;</span><span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><span class="linecomment">;;</span><span class="linecomment">;;; Code:</span><span class="linecomment">;;>> Problem: Tabs at beginning of lines</span>(and (< emacs-major-version 20) (eval-when-compile (require 'cl))) <span class="linecomment">;; when, unless</span><span class="linecomment">;;;;;;;;;;;;;</span><span class="linecomment">;;;###autoload</span>(defun display-line-numbers () "<span class="quote">Temporarily display line numbers in left margin of current buffer.</span>" (interactive) (or (eq (current-buffer) (window-buffer (selected-window))) (error "<span class="quote">Current buffer, %s, is not the selected window's buffer</span>" (buffer-name))) (let ((buffer-read-only nil) (modified (buffer-modified-p)) (name buffer-file-name) (point (point-marker)) format-string line-number (count 0) nlines first-line) (save-restriction (widen) (save-excursion (setq first-line (window-start (selected-window))) (goto-char first-line) (setq line-number (1+ (count-lines (point-min) (point)))) (move-to-window-line -1) (beginning-of-line) (setq nlines (count-lines first-line (point))) (let ((max (+ line-number nlines))) (setq format-string (cond ((< max 100) "<span class="quote">%2d </span>") ((< max 1000) "<span class="quote">%3d </span>") ((< max 10000) "<span class="quote">%4d </span>") (t "<span class="quote">%7d </span>")))))) (save-excursion (unwind-protect (progn (goto-char first-line) <span class="linecomment">;; defeat file locking... don't try this at home, kids!</span> (setq buffer-file-name nil) (while (<= count nlines) (insert-before-markers (format format-string line-number)) <span class="linecomment">;;;(setq insert-end (point)) THIS VAR IS FREE - AND UNUSED!</span> (setq line-number (1+ line-number)) (setq count (1+ count)) (forward-line 1)) (set-window-start (selected-window) first-line) (goto-char point) (set-buffer-modified-p modified) (message "<span class="quote"><<< Press SPACE to continue >>></span>") (let ((char (read-char))) (or (eql char ?\ ) (setq unread-command-events (list char)))) ) (goto-char first-line) (let ((n (1+ (- (aref format-string 1) ?0)))) (while (> count 0) (setq count (1- count)) (delete-char n) (forward-line 1))) (setq buffer-file-name name) (set-buffer-modified-p modified)))))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -