diff options
| author | Stefan Monnier | 2017-09-27 13:00:44 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2017-09-27 13:00:44 -0400 |
| commit | 56f7e4c2024608b2a263dc8505c49996cda0ec4f (patch) | |
| tree | c9fe5b6a0c62bcb56f600541ce4defeeddbbb45a | |
| parent | a17f30d7cdfa3983f8c97e474015777ec051de35 (diff) | |
| download | emacs-56f7e4c2024608b2a263dc8505c49996cda0ec4f.tar.gz emacs-56f7e4c2024608b2a263dc8505c49996cda0ec4f.zip | |
* lisp/textmodes/page-ext.el: Misc cleanup, add RET binding
Use lexical-binding.
Remove redundant :group args.
(pages-directory-mode-map): Bind RET.
(pages-buffer, pages-pos-list): Define as buffer-local.
(pages-directory-map): Define as alias *before* the defvar.
Mark as obsolete.
(pages-buffer-original-position, pages-buffer-original-page):
Move declaration to before the first use.
(pages-directory): Remove unused var `linenum`.
(pages-directory-goto): Add optional `event` arg and make it work when
bound to mouse events.
(pages-directory-goto-with-mouse): Make it an obsolete alias.
| -rw-r--r-- | lisp/textmodes/page-ext.el | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/lisp/textmodes/page-ext.el b/lisp/textmodes/page-ext.el index 94b68decfb7..bf1e33bf0f6 100644 --- a/lisp/textmodes/page-ext.el +++ b/lisp/textmodes/page-ext.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; page-ext.el --- extended page handling commands | 1 | ;;; page-ext.el --- extended page handling commands -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1990-1991, 1993-1994, 2001-2017 Free Software | 3 | ;; Copyright (C) 1990-1991, 1993-1994, 2001-2017 Free Software |
| 4 | ;; Foundation, Inc. | 4 | ;; Foundation, Inc. |
| @@ -243,18 +243,15 @@ | |||
| 243 | 243 | ||
| 244 | (defcustom pages-directory-buffer-narrowing-p t | 244 | (defcustom pages-directory-buffer-narrowing-p t |
| 245 | "If non-nil, `pages-directory-goto' narrows pages buffer to entry." | 245 | "If non-nil, `pages-directory-goto' narrows pages buffer to entry." |
| 246 | :type 'boolean | 246 | :type 'boolean) |
| 247 | :group 'pages) | ||
| 248 | 247 | ||
| 249 | (defcustom pages-directory-for-adding-page-narrowing-p t | 248 | (defcustom pages-directory-for-adding-page-narrowing-p t |
| 250 | "If non-nil, `add-new-page' narrows page buffer to new entry." | 249 | "If non-nil, `add-new-page' narrows page buffer to new entry." |
| 251 | :type 'boolean | 250 | :type 'boolean) |
| 252 | :group 'pages) | ||
| 253 | 251 | ||
| 254 | (defcustom pages-directory-for-adding-new-page-before-current-page-p t | 252 | (defcustom pages-directory-for-adding-new-page-before-current-page-p t |
| 255 | "If non-nil, `add-new-page' inserts new page before current page." | 253 | "If non-nil, `add-new-page' inserts new page before current page." |
| 256 | :type 'boolean | 254 | :type 'boolean) |
| 257 | :group 'pages) | ||
| 258 | 255 | ||
| 259 | 256 | ||
| 260 | ;;; Addresses related variables | 257 | ;;; Addresses related variables |
| @@ -262,23 +259,19 @@ | |||
| 262 | (defcustom pages-addresses-file-name "~/addresses" | 259 | (defcustom pages-addresses-file-name "~/addresses" |
| 263 | "Standard name for file of addresses. Entries separated by page-delimiter. | 260 | "Standard name for file of addresses. Entries separated by page-delimiter. |
| 264 | Used by `pages-directory-for-addresses' function." | 261 | Used by `pages-directory-for-addresses' function." |
| 265 | :type 'file | 262 | :type 'file) |
| 266 | :group 'pages) | ||
| 267 | 263 | ||
| 268 | (defcustom pages-directory-for-addresses-goto-narrowing-p t | 264 | (defcustom pages-directory-for-addresses-goto-narrowing-p t |
| 269 | "If non-nil, `pages-directory-goto' narrows addresses buffer to entry." | 265 | "If non-nil, `pages-directory-goto' narrows addresses buffer to entry." |
| 270 | :type 'boolean | 266 | :type 'boolean) |
| 271 | :group 'pages) | ||
| 272 | 267 | ||
| 273 | (defcustom pages-directory-for-addresses-buffer-keep-windows-p t | 268 | (defcustom pages-directory-for-addresses-buffer-keep-windows-p t |
| 274 | "If nil, `pages-directory-for-addresses' deletes other windows." | 269 | "If nil, `pages-directory-for-addresses' deletes other windows." |
| 275 | :type 'boolean | 270 | :type 'boolean) |
| 276 | :group 'pages) | ||
| 277 | 271 | ||
| 278 | (defcustom pages-directory-for-adding-addresses-narrowing-p t | 272 | (defcustom pages-directory-for-adding-addresses-narrowing-p t |
| 279 | "If non-nil, `add-new-page' narrows addresses buffer to new entry." | 273 | "If non-nil, `add-new-page' narrows addresses buffer to new entry." |
| 280 | :type 'boolean | 274 | :type 'boolean) |
| 281 | :group 'pages) | ||
| 282 | 275 | ||
| 283 | 276 | ||
| 284 | ;;; Key bindings for page handling functions | 277 | ;;; Key bindings for page handling functions |
| @@ -415,9 +408,9 @@ Point is left in the body of page." | |||
| 415 | Called from a program, there are three arguments: | 408 | Called from a program, there are three arguments: |
| 416 | REVERSE (non-nil means reverse order), BEG and END (region to sort)." | 409 | REVERSE (non-nil means reverse order), BEG and END (region to sort)." |
| 417 | 410 | ||
| 418 | ;;; This sort function handles ends of pages differently than | 411 | ;; This sort function handles ends of pages differently than |
| 419 | ;;; `sort-pages' and works better with lists of addresses and similar | 412 | ;; `sort-pages' and works better with lists of addresses and similar |
| 420 | ;;; files. | 413 | ;; files. |
| 421 | 414 | ||
| 422 | (interactive "P\nr") | 415 | (interactive "P\nr") |
| 423 | (save-restriction | 416 | (save-restriction |
| @@ -463,25 +456,27 @@ REVERSE (non-nil means reverse order), BEG and END (region to sort)." | |||
| 463 | \(This regular expression may be used to select only those pages that | 456 | \(This regular expression may be used to select only those pages that |
| 464 | contain matches to the regexp.)") | 457 | contain matches to the regexp.)") |
| 465 | 458 | ||
| 466 | (defvar pages-buffer nil | 459 | (defvar-local pages-buffer nil |
| 467 | "The buffer for which the pages-directory function creates the directory.") | 460 | "The buffer for which the pages-directory function creates the directory.") |
| 468 | 461 | ||
| 469 | (defvar pages-directory-prefix "*Directory for:" | 462 | (defvar pages-directory-prefix "*Directory for:" |
| 470 | "Prefix of name of temporary buffer for pages-directory.") | 463 | "Prefix of name of temporary buffer for pages-directory.") |
| 471 | 464 | ||
| 472 | (defvar pages-pos-list nil | 465 | (defvar-local pages-pos-list nil |
| 473 | "List containing the positions of the pages in the pages-buffer.") | 466 | "List containing the positions of the pages in the pages-buffer.") |
| 474 | 467 | ||
| 475 | (defvar pages-target-buffer) | 468 | (defvar pages-target-buffer) |
| 476 | 469 | ||
| 470 | (define-obsolete-variable-alias 'pages-directory-map | ||
| 471 | 'pages-directory-mode-map "26.1") | ||
| 477 | (defvar pages-directory-mode-map | 472 | (defvar pages-directory-mode-map |
| 478 | (let ((map (make-sparse-keymap))) | 473 | (let ((map (make-sparse-keymap))) |
| 479 | (define-key map "\C-c\C-c" 'pages-directory-goto) | 474 | (define-key map "\C-c\C-c" 'pages-directory-goto) |
| 475 | (define-key map "\C-m" 'pages-directory-goto) | ||
| 480 | (define-key map "\C-c\C-p\C-a" 'add-new-page) | 476 | (define-key map "\C-c\C-p\C-a" 'add-new-page) |
| 481 | (define-key map [mouse-2] 'pages-directory-goto-with-mouse) | 477 | (define-key map [mouse-2] 'pages-directory-goto) |
| 482 | map) | 478 | map) |
| 483 | "Keymap for the pages-directory-buffer.") | 479 | "Keymap for the pages-directory-buffer.") |
| 484 | (defvaralias 'pages-directory-map 'pages-directory-mode-map) | ||
| 485 | 480 | ||
| 486 | (defvar original-page-delimiter "^\f" | 481 | (defvar original-page-delimiter "^\f" |
| 487 | "Default page delimiter.") | 482 | "Default page delimiter.") |
| @@ -512,6 +507,9 @@ resets the page-delimiter to the original value." | |||
| 512 | 507 | ||
| 513 | ;;; Pages directory main definitions | 508 | ;;; Pages directory main definitions |
| 514 | 509 | ||
| 510 | (defvar pages-buffer-original-position) | ||
| 511 | (defvar pages-buffer-original-page) | ||
| 512 | |||
| 515 | (defun pages-directory | 513 | (defun pages-directory |
| 516 | (pages-list-all-headers-p count-lines-p &optional regexp) | 514 | (pages-list-all-headers-p count-lines-p &optional regexp) |
| 517 | "Display a directory of the page headers in a temporary buffer. | 515 | "Display a directory of the page headers in a temporary buffer. |
| @@ -573,7 +571,6 @@ directory for only the accessible portion of the buffer." | |||
| 573 | (let ((pages-target-buffer (current-buffer)) | 571 | (let ((pages-target-buffer (current-buffer)) |
| 574 | (pages-directory-buffer | 572 | (pages-directory-buffer |
| 575 | (concat pages-directory-prefix " " (buffer-name))) | 573 | (concat pages-directory-prefix " " (buffer-name))) |
| 576 | (linenum 1) | ||
| 577 | (pages-buffer-original-position (point)) | 574 | (pages-buffer-original-position (point)) |
| 578 | (pages-buffer-original-page 0)) | 575 | (pages-buffer-original-page 0)) |
| 579 | 576 | ||
| @@ -644,10 +641,6 @@ directory for only the accessible portion of the buffer." | |||
| 644 | 1 | 641 | 1 |
| 645 | pages-buffer-original-page)))) | 642 | pages-buffer-original-page)))) |
| 646 | 643 | ||
| 647 | (defvar pages-buffer-original-position) | ||
| 648 | (defvar pages-buffer-original-page) | ||
| 649 | (defvar pages-buffer-original-page) | ||
| 650 | |||
| 651 | (defun pages-copy-header-and-position (count-lines-p) | 644 | (defun pages-copy-header-and-position (count-lines-p) |
| 652 | "Copy page header and its position to the Pages Directory. | 645 | "Copy page header and its position to the Pages Directory. |
| 653 | Only arg non-nil, count lines in page and insert before header. | 646 | Only arg non-nil, count lines in page and insert before header. |
| @@ -701,16 +694,13 @@ Used by `pages-directory' function." | |||
| 701 | 694 | ||
| 702 | Move point to one of the lines in this buffer, then use \\[pages-directory-goto] to go | 695 | Move point to one of the lines in this buffer, then use \\[pages-directory-goto] to go |
| 703 | to the same line in the pages buffer." | 696 | to the same line in the pages buffer." |
| 704 | (make-local-variable 'pages-buffer) | ||
| 705 | (make-local-variable 'pages-pos-list) | ||
| 706 | (make-local-variable 'pages-directory-buffer-narrowing-p)) | 697 | (make-local-variable 'pages-directory-buffer-narrowing-p)) |
| 707 | 698 | ||
| 708 | (defun pages-directory-goto () | 699 | (defun pages-directory-goto (&optional event) |
| 709 | "Go to the corresponding line in the pages buffer." | 700 | "Go to the corresponding line in the pages buffer." |
| 710 | 701 | ;; This function is mostly a copy of `occur-mode-goto-occurrence' | |
| 711 | ;;; This function is mostly a copy of `occur-mode-goto-occurrence' | 702 | (interactive "@e") |
| 712 | 703 | (if event (mouse-set-point event)) | |
| 713 | (interactive) | ||
| 714 | (if (or (not pages-buffer) | 704 | (if (or (not pages-buffer) |
| 715 | (not (buffer-name pages-buffer))) | 705 | (not (buffer-name pages-buffer))) |
| 716 | (progn | 706 | (progn |
| @@ -724,18 +714,13 @@ to the same line in the pages buffer." | |||
| 724 | (narrowing-p pages-directory-buffer-narrowing-p)) | 714 | (narrowing-p pages-directory-buffer-narrowing-p)) |
| 725 | (pop-to-buffer pages-buffer) | 715 | (pop-to-buffer pages-buffer) |
| 726 | (widen) | 716 | (widen) |
| 727 | (if end-of-directory-p | 717 | (goto-char (if end-of-directory-p |
| 728 | (goto-char (point-max)) | 718 | (point-max) |
| 729 | (goto-char (marker-position pos))) | 719 | (marker-position pos))) |
| 730 | (if narrowing-p (narrow-to-page)))) | 720 | (if narrowing-p (narrow-to-page)))) |
| 731 | 721 | ||
| 732 | (defun pages-directory-goto-with-mouse (event) | 722 | (define-obsolete-function-alias 'pages-directory-goto-with-mouse |
| 733 | "Go to the corresponding line under the mouse pointer in the pages buffer." | 723 | #'pages-directory-goto "26.1") |
| 734 | (interactive "e") | ||
| 735 | (with-current-buffer (window-buffer (posn-window (event-end event))) | ||
| 736 | (save-excursion | ||
| 737 | (goto-char (posn-point (event-end event))) | ||
| 738 | (pages-directory-goto)))) | ||
| 739 | 724 | ||
| 740 | ;;; The `pages-directory-for-addresses' function and ancillary code | 725 | ;;; The `pages-directory-for-addresses' function and ancillary code |
| 741 | 726 | ||