Timeline for Why is this function not working properly, when added to a hook?
Current License: CC BY-SA 3.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 9, 2015 at 23:45 | vote | accept | ReneFroger | ||
| Oct 9, 2015 at 23:42 | comment | added | ReneFroger | Thanks Drew, changing the emacs-lisp-mode-hook to nil did do the trick. I think that file-visiting functions that invoke mode hooks would not be a problem, because I intend to use it only for WSD-mode, and all WSD-files are stored in a map, hence the hook. | |
| Oct 8, 2015 at 20:49 | comment | added | Drew | Yes, because find-alternate-file calls find-file, which itself applies the mode hook. You can work around that by binding emacs-lisp-mode-hook to nil in the same let. But really you should not be calling a function that visits a file from within a mode hook - you will always run into the same problem, since file-visiting functions invoke mode hooks. What you probably want to do is use find-file-hook instead, and test in for the mode in the hook function. | |
| Oct 8, 2015 at 20:47 | history | edited | Drew | CC BY-SA 3.0 | added 67 characters in body |
| Oct 8, 2015 at 19:06 | comment | added | ReneFroger | Drew, thanks for willing to help me out, I made a screencast to illustrate my problem with your code snippet: i.imgur.com/Ph6Hi5a.gifv And M-x debug-on-entry, then typing change-to-foobar-directory, gives me no results. I use GUI version GNU Emacs 25.0.50.1 (x86_64-w64-mingw32) by the way. of 2015-07-25 on KAEL | |
| Oct 6, 2015 at 13:49 | comment | added | Drew | Provide a recipe of what you're doing, starting from emacs -Q. Include info about what buffer you are starting in, what other buffers exist, etc. Or M-x debug-on-entry change-to-foobar-directory and step through the debugger, to see what the problem is. The **lose** buffer is from find-alternate-file, which should not get called unless the buffer you are in is visiting a file. Start with a simple case of a file in the same dir - see if the problem has to do with which file you try to find. | |
| Oct 6, 2015 at 7:12 | comment | added | ReneFroger | Drew, thanks for your helpful comments. I have read the documentation about file names. And your function still doesn't work, by the way. I end up in the lose buffer, and I got the message File mode specification error: (error: "Selecting deleted buffer"). Another suggestion? | |
| Oct 5, 2015 at 22:22 | comment | added | Drew | I've edited the post so that the function should now be a no-op if the current buffer is not visiting a file. In the absence of a clear spec of what behavior you want in that case, this seems reasonable. | |
| Oct 5, 2015 at 22:21 | history | edited | Drew | CC BY-SA 3.0 | added 359 characters in body |
| Oct 5, 2015 at 22:19 | comment | added | Drew | (This Q&A have nothing to do with OneOnOneEmacs, which you referenced.) | |
| Oct 5, 2015 at 22:17 | comment | added | Drew | expand-file-name and the other file-name manipulating functions are designed for, well, manipulating file names. They can be used in multiple contexts, including different platforms and remote hosts. concat sees only strings, not file names. Again, consider reading some of the doc I pointed you to. | |
| Oct 5, 2015 at 22:16 | comment | added | Drew | buffer-file-name is only for buffers visiting files. If used in another buffer (not associated with a file) it returns nil, which is probably the problem you are encountering. In that case, you would need to specify what behavior you want, for such a buffer. OK, you want to kill it. But do you really want to open a file with the same name as that non-file buffer (e.g. *scratch* or whatever)? Not clear to me what the aim is in this case. | |
| Oct 5, 2015 at 18:47 | comment | added | ReneFroger | Your solution didn't worked, got the message "Note: file is write protected" and the buffer name is a concenation of previous directory path and new path. However your code seems faulty (Sorry, I consider you as the master in Lisp) I would like to learn from it: 1. What is the difference between buffer-file-name and buffer-name? 2. Why prefering the expand-file-name above concat, while the result would be the same? 3. Your project is discussed here. | |
| Oct 5, 2015 at 15:54 | history | edited | Drew | CC BY-SA 3.0 | added 190 characters in body |
| Oct 5, 2015 at 15:27 | history | edited | Drew | CC BY-SA 3.0 | added 5 characters in body |
| Oct 5, 2015 at 15:21 | history | answered | Drew | CC BY-SA 3.0 |