unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Glenn Morris <rgm@gnu.org>
Cc: 17482@debbugs.gnu.org
Subject: bug#17482: args-out-of-range when visiting foo.todo
Date: Tue, 13 May 2014 17:57:04 +0200	[thread overview]
Message-ID: <87zjilzn73.fsf@rosalinde.fritz.box> (raw)
In-Reply-To: <g461la19lg.fsf@fencepost.gnu.org> (Glenn Morris's message of "Tue, 13 May 2014 02:22:35 -0400")

On Tue, 13 May 2014 02:22:35 -0400 Glenn Morris <rgm@gnu.org> wrote:

> Package: emacs
> Version: 24.3.91
> Severity: important
>
> emacs -Q
> C-x C-f /tmp/foo.todo
>   -> args-out-of-range error
>
> (.todo is a pretty generic extension for me. I don't want it to open a
> specialized Emacs mode. I don't feel strongly about it though.
> Perhaps the NEWS file should say that .todo files now open in todo-mode.
> They didn't before.)

Perhaps it was presumptuous of me to appropriate the .todo extension for
Todo mode.  I'm not aware of any policy about this, and I do see that a
number of modes add an extension to auto-mode-alist unconditionally,
while others merely suggest doing that in the user's init file.
However, I've come up with the following fix, which keeps automatic
recognition of Todo mode files located in `todo-directory', which is
where all Todo mode files are stored, but allows you to create and visit
foo.todo in the default major mode anywhere else.  If this works for you
and it's not an unacceptable abuse of auto-mode-alist, I'll commit it to
emacs-24.  Thanks for the report.

Steve Berman

=== modified file 'lisp/calendar/todo-mode.el'
*** lisp/calendar/todo-mode.el	2014-05-09 07:50:42 +0000
--- lisp/calendar/todo-mode.el	2014-05-13 15:37:39 +0000
***************
*** 6401,6411 ****
  
  (defun todo-display-as-todo-file ()
    "Show todo files correctly when visited from outside of Todo mode.
! Added to `find-file-hook' in Todo mode and Todo Archive mode."
!   (and (member this-command todo-visit-files-commands)
!        (= (- (point-max) (point-min)) (buffer-size))
!        (member major-mode '(todo-mode todo-archive-mode))
!        (todo-category-select)))
  
  (defun todo-add-to-buffer-list ()
    "Add name of just visited todo file to `todo-file-buffers'.
--- 6401,6425 ----
  
  (defun todo-display-as-todo-file ()
    "Show todo files correctly when visited from outside of Todo mode.
! Added to `find-file-hook' in Todo mode, Todo Archive mode and
! Todo Filtered Items mode.
! 
! This is intended only for visiting an existing todo, archive, or
! filtered items file, and signals an error if you try to create a
! new one using, e.g., `find-file'."
!   (if (equal (file-truename todo-directory)
! 	     (file-name-directory (file-truename (buffer-file-name))))
!       (when (member this-command todo-visit-files-commands)
! 	(if (> (buffer-size) 0)
! 	    (and (= (- (point-max) (point-min)) (buffer-size))
! 		 (memq major-mode '(todo-mode todo-archive-mode))
! 		 (todo-category-select))
! 	  (kill-buffer)
! 	  (user-error "To add a new todo file, type %s in Todo mode"
! 		      (substitute-command-keys "\\[todo-add-file]"))))
!     (kill-all-local-variables)
!     (setq buffer-read-only nil)
!     (set-buffer-major-mode (current-buffer))))
  
  (defun todo-add-to-buffer-list ()
    "Add name of just visited todo file to `todo-file-buffers'.
***************
*** 6454,6459 ****
--- 6468,6474 ----
    "Make some settings that apply to multiple Todo modes."
    (add-to-invisibility-spec 'todo)
    (setq buffer-read-only t)
+   (add-hook 'find-file-hook 'todo-display-as-todo-file nil t)
    (when (and (boundp 'desktop-save-mode) desktop-save-mode)
      (setq-local desktop-save-buffer 'todo-desktop-save-buffer))
    (when (boundp 'hl-line-range-function)
***************
*** 6466,6473 ****
  (defun todo-modes-set-3 ()
    "Make some settings that apply to multiple Todo modes."
    (setq-local todo-categories (todo-set-categories))
!   (setq-local todo-category-number 1)
!   (add-hook 'find-file-hook 'todo-display-as-todo-file nil t))
  
  (put 'todo-mode 'mode-class 'special)
  
--- 6481,6487 ----
  (defun todo-modes-set-3 ()
    "Make some settings that apply to multiple Todo modes."
    (setq-local todo-categories (todo-set-categories))
!   (setq-local todo-category-number 1))
  
  (put 'todo-mode 'mode-class 'special)
  
***************
*** 6555,6566 ****
    (todo-modes-set-1)
    (todo-modes-set-2))
  
  ;;;###autoload
! (add-to-list 'auto-mode-alist '("\\.todo\\'" . todo-mode))
  ;;;###autoload
! (add-to-list 'auto-mode-alist '("\\.toda\\'" . todo-archive-mode))
  ;;;###autoload
! (add-to-list 'auto-mode-alist '("\\.tod[tyr]\\'" . todo-filtered-items-mode))
  
  ;; -----------------------------------------------------------------------------
  (provide 'todo-mode)
--- 6569,6607 ----
    (todo-modes-set-1)
    (todo-modes-set-2))
  
+ ;; All Todo mode files reside in `todo-directory', but maybe the user
+ ;; wants to be able to have files with these extensions in other modes
+ ;; elsewhere (bug#17482).  So we conditionalize automatic major mode
+ ;; selection on the file's location.
+ 
+ ;;;###autoload
+ (defun todo-maybe-todo-mode ()
+   (if (equal (file-truename todo-directory)
+ 	     (file-name-directory (file-truename (buffer-file-name))))
+       (todo-mode)
+     (set-buffer-major-mode (current-buffer))))
+ 
+ ;;;###autoload
+ (defun todo-maybe-todo-archive-mode ()
+   (if (equal (file-truename todo-directory)
+ 	     (file-name-directory (file-truename (buffer-file-name))))
+       (todo-archive-mode)
+     (set-buffer-major-mode (current-buffer))))
+ 
+ ;;;###autoload
+ (defun todo-maybe-todo-filtered-items-mode ()
+   (if (equal (file-truename todo-directory)
+ 	     (file-name-directory (file-truename (buffer-file-name))))
+       (todo-filtered-items-mode)
+     (set-buffer-major-mode (current-buffer))))
+ 
  ;;;###autoload
! (add-to-list 'auto-mode-alist '("\\.todo\\'" . todo-maybe-todo-mode))
  ;;;###autoload
! (add-to-list 'auto-mode-alist '("\\.toda\\'" . todo-maybe-todo-archive-mode))
  ;;;###autoload
! (add-to-list 'auto-mode-alist
! 	     '("\\.tod[tyr]\\'" . todo-maybe-todo-filtered-items-mode))
  
  ;; -----------------------------------------------------------------------------
  (provide 'todo-mode)






  reply	other threads:[~2014-05-13 15:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-13  6:22 bug#17482: args-out-of-range when visiting foo.todo Glenn Morris
2014-05-13 15:57 ` Stephen Berman [this message]
2014-05-13 16:02   ` Glenn Morris
2014-05-13 16:26     ` Stephen Berman
2014-05-13 19:40   ` Stefan Monnier
2014-05-13 22:33     ` Stephen Berman
2014-05-14  3:22       ` Stefan Monnier
2014-05-14 15:10         ` Stephen Berman
2014-05-14 16:55           ` Stefan Monnier
2014-05-14 17:46             ` Glenn Morris
2014-05-14 19:57               ` Stephen Berman
2014-05-14 20:01                 ` Glenn Morris
2014-05-14 20:34                   ` Stephen Berman
2014-05-14 21:44                     ` Stefan Monnier
2014-05-14 21:58                       ` Stephen Berman
2014-05-15  2:24                         ` Stefan Monnier
2014-05-23 16:59                 ` Stephen Berman
2014-05-23 17:32                   ` Glenn Morris
2014-05-23 19:12                     ` Stephen Berman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjilzn73.fsf@rosalinde.fritz.box \
    --to=stephen.berman@gmx.net \
    --cc=17482@debbugs.gnu.org \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).