[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Seeking advice on writing a "line-based" major mode
From: |
Emanuel Berg |
Subject: |
Re: Seeking advice on writing a "line-based" major mode |
Date: |
Fri, 19 Jun 2015 00:01:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Emanuel Berg <embe8573@student.uu.se> writes:
> I think there are two schools how to do this.
>
> The easiest way and the way I would do it is to just
> write an iteration (or recursive) algorithm to
> populate the window with data, which will also serve
> as the UI.
>
> Simply have a key (e.g., RET) execute an algorithm to
> act on the data:
>
> (let ((data (thing-at-point ... ))) (if ( ...
> data) (action data) ... ))
Here is an example of this method - or check out the
file here:
http://user.it.uu.se/~embe8573/line-file-table.el
See that last comment block for how to invoke AND an
interesting thing with point position that differs in
byte-compiled vs. normal mode.
(defun find-file-at-line (&optional other-window)
(interactive "P")
(let ((possible-filename (thing-at-point 'filename))
(find-f (if other-window 'find-file-other-window 'find-file)) )
(if (and possible-filename (file-exists-p possible-filename))
(apply find-f `(,possible-filename))
(progn
(forward-char 1)
(find-file-at-line) ))))
(defvar *files* '("~/.emacs" "~/.gnus" "~/.zshrc" "~/.zshenv"))
(defun make-table ()
(insert ";; Either press M-RET or M-r to visit a file.\n"
";; If a file doesn't exist, the next one is tried.\n;;\n" )
(save-excursion ; [1]
(dolist (f *files*)
(insert (format ";; %s\n" f)) )))
(local-set-key "\M-\r" 'find-file-at-line) ; M-RET
(local-set-key "\M-r" 'find-file-at-line) ; M-r
(make-table)
;; [1] for whatever reason (?) this isn't applied with
;;
;; emacs -Q -l ~/line-file-table.el
;;
;; but if compiled first
;;
;; emacs --batch -f batch-byte-compile ~/line-file-table.el;
;; emacs -Q -l ~/line-file-table.elc
;;
;; then it works.
--
underground experts united
http://user.it.uu.se/~embe8573
- Seeking advice on writing a "line-based" major mode, Marcin Borkowski, 2015/06/07
- RE: Seeking advice on writing a "line-based" major mode, Drew Adams, 2015/06/07
- Re: Seeking advice on writing a "line-based" major mode, Marcin Borkowski, 2015/06/18
- RE: Seeking advice on writing a "line-based" major mode, Drew Adams, 2015/06/18
- Re: Seeking advice on writing a "line-based" major mode, Marcin Borkowski, 2015/06/18
- RE: Seeking advice on writing a "line-based" major mode, Drew Adams, 2015/06/18
- Re: Seeking advice on writing a "line-based" major mode, Marcin Borkowski, 2015/06/18
- RE: Seeking advice on writing a "line-based" major mode, Drew Adams, 2015/06/18
- Message not available
- Re: Seeking advice on writing a "line-based" major mode, Emanuel Berg, 2015/06/18
Message not available
Re: Seeking advice on writing a "line-based" major mode, Tom Tromey, 2015/06/08