last day (25 days later) » 

2:06 PM
-3
Q: How to make Emacs react to SIGUSR1 and reload config file?

Inspired_BluePROBLEM-STATEMENT: I want to build something like urxvt-config-reload for emacs. That is, I want to run M-x load-file ~/.emacs upon receiving SIGUSR1 using kill -USR1 <emacs pid>. MY PROGRESS SO FAR: I have tried to tinker with the code from this emacs stack-exchange post. Yes I was able to...

 
The argument to load-file needs to be a string; this should be easy enough to google. Please, only one question per question, and show us what you tried.
There is no expectation or guarantee that executing an arbitrary .emacs file a second time is useful and produces no ill side effects. A well-written .emacs will basically be a no-op if you run it again, but most will probably do things they shouldn't.
A better design, then, might be to have a separate configuration file with additional conventions to make it idempotent (i.e. robust to reload) and load that instead. The conventional way to completely restart Emacs remains ... a proper restart.
 
Thanks for the hints. The first problem was easily solved: (load-file "~/.emacs"). I am very new to elisp.
 
Then please edit your question to remove the trivial part and show where you are with the hard part.
Or if that actually solved your problem, probably simply delete this question.
 
I have made the edits. Thanks for the feedback.
I understand your concerns about good design philosophy. Yes I have been careful/ aware to make sure that I don't have anything in my config that breaks on re-loading. But I want to be able to update all my emacs instances as soon as I change my config. So the question really is how do I update all my emacs instances without having to visit them and doing M-x load-file on each instance. Or to close all my instances and restart them all over again.
Should I repost this question? I have been down-voted?!
 
Reposting is completely the wrong response. You might be able to salvage this by editing but so far, you seem to be ignoring my suggestions. See also help and this checklist
Running multiple Emacs instances is also suspicious; look into using emacsclient instead.
 
2:06 PM
Thanks for helping. I will try to edit the question.
I am aware of emacsclient. I use it. But sometimes I prefer multiple instance to leverage the power of tiling manager. You are sermonizing your design aesthetics here.
Hi, can you help me with figuring out how to make emacs react to SIGUSR1? At least do you have some hints.
I wish I had the time to learn lisp and do it right. But for now I am willing to live by borrowed wisdom.
Or can you please your editorial skills and edit the question to something that is more appropriate and useful for the stackexchange community?
Here is question: emacs.stackexchange.com/questions/33974/… that is 2 years old and has been upvoited twice. I believe the seasoned emac-er would be able to solve it pretty easily. But there has been no answer to this question.
I am trying to solve the above problem using $SIGUSR1. If you have better ideas please also let me know.
Or can you please use (typo) your editorial skills and edit the question to something that is more appropriate and useful for the stackexchange community?
Please help me.
 
2:22 PM
so does the obvious thing not work?
(not really in a place where I can chat; pardon any typos)
the obvious thing being, replace the (message...) form in the demo with your load-file form
 
i see. That is an useful suggestion.
Let me see how far I get.
(I mean lisp is an enigma for me at this moment. Sorry. :) )
Thanks for taking the time. I have deleted the question.
Please let me know if you feel there is merit in reviving it later for the community.
 
2:53 PM
as already suggested, if you can show what you tried and how it failed it could be useful for future visitors, but maybe show the backtrace here first if you get an error
Lisp is superficially very simple, the evaluation order is exactly what you expect from the mathematical meaning of parentheses, and on top of that you just need to understand bare symbols vs quoted symbols and strings
plus the convention that the first symbol in an unquoted list is a function call
 
Nice. Thanks for quick lisp tutorial.
I tried the following:
(defun sigusr-handler ()
(interactive)
(load-file "~\.emacs" last-input-event))
(define-key special-event-map [sigusr1] 'sigusr-handler)
But that doesn't work :(
The error I get is: Wrong number of arguments: (1 . 1), 2
 
the backslash should be a slash
 
I googling that error now
Ohh..
 
and why do you supply last-input-event; what do you hope for that to accomplish?
 
I want to make sure that above code executes only when I get the SIGUSR signal.
It is not clear to me where in the code that is being specified
To me it seems, this code would work for both SIGUSR1 and SIGUSR2. If so, I would want it to work exclusively with SIGUSR1.
Btw the backslash is the correct thing to do. The slash doesn't work.
 
3:26 PM
Thanks I could fix it:
(defun sigusr-handler ()
(interactive)
(load-file "~/.emacs"))
(define-key special-event-map [sigusr1] 'sigusr-handler)
And also it is (define-key special-event-map [sigusr1] 'sigusr-handler) which triggers the function `sigusr-handler
So for sigusr2 I would so something like (define-key special-event-map [sigusr2] function-name)`
The above code does the job. But it still a mystery how it is working. I will play around a bit more and hopefully learn some more about lisp.
Thank you so so so much for your time!
"plus the convention that the first symbol in an unquoted list is a function call" -- this I didn't know for example. It clarified some part of what is going on in the code.
 
3:44 PM
what you name the function is inconsequential; call it sigusr1-handler if you like and/or it describes its purpose better
 
true. sigusr1-handler is a fair name.
 
the main weird thing I guess is that the signals get synthesized into keystrokes
i.e. the usual purpose of define-key is to configure the handling of a user keystroke like the a key or C-c C-x
(I didn't know that, so thanks for this information about how signals are handled :-)
 
I see. Thanks for clarifying that. Yes it is interesting that signals get synthetized into keystrokes and so define-key captures them.
I don't understand what kind of object is last-input-event
When I try C-h f and type last-input-event I don't get anything
However there is a mention of this on gnu.org/software/emacs/manual/html_node/elisp/…
It says "This variable..."
 
re: the link to loading .Xresources I guess that's not really relevant any longer? Probably it's easy to do in isolation but the implications are vaguely similar to the caveats I noted for your question - the proper solution needs to explain much more about how X resources are generally handled (but I'm waving my hands a bit here)
 
So last-input-event is not a function? I had some vague impression that in lisp data and program as supposed to be interchangeable. Yes lisp is interesting.
 
3:57 PM
last-input-event is the latest mouse click or keystroke, like the name implies - it's mainly important if you need to figure out what triggered an interactive function (often just to pass it on, i.e. "I don't know which key you pressed and actually I don't care, either; but I have to pass it on to this other function which also requires this"information)
 
Why is there no entry for it under C-h f?
 
"programs are data" means you can interpret a list as either just a sequence of symbols (data) or instructions (these are Lisp symbols with specific semantics)
@Inspired_Blue because it's not a function, variable documentation is on C-h v
 
I see. Got it. Thanks.
And can you demystify the %s construct?
At first I read it like the $1 is bash
But it is not
But seems like a lot to parse at one go
 
in isolation %s is not meaningful to me but I guess you mean as a format string?
 
For example what is it doing in here (message "Caught signal %S" last-input-event)
This is from the code that I edited and replaced with the (load-file ...)
 
4:03 PM
so it's like printf("%s", "string here) in C but there are many different places where it can have a more specific meaning - the modeline documentation you linked to is indeed very specific to just the formatting of the mode line
that's uppercase %S so again a different symbol but probably the message documentation has at least a pointer to what symbols you can use there
 
I see. Thanks. My great confusion was because I read it as $1 is bash or \1 in reg-ex
Yes I will check the message documentation
When executed it used to return sigusr1 in the message
So I think it points to function that called it here
Yes that is a %S with capital S
 
you have printf in Bash too, with specific Bash specialties like printf %q "$variable" to produce the variable's value properly quoted
 
yes. I get it now
And one last thing to help me sort of complete my recipe
when I apply something like `(custom-set-faces
'(default ((t (:background "#2d2d2d" :foreground "#d3d0c8" :height 100 :width normal :foundry "DAMA" :family "Ubuntu Mono"))))))`
and eval-buffer it the changes immediately takes place
(That is what I verified by triggering sigusr1)
Even if I eval-buffer this the changes take place only when I close and restart emacs
Why is this so?
Or put differently, How do I change the github code so that when I eval-buffer it, the changes take place immediately without having to wait for a restart
 
no time to read the code properly but a common arrangement is for mode definitions to just declare things (like your defun) but not invoke them (like when you actually send the signal)
if you know Python, compare to the common if __name__ == '__main__': convention
 
Nope. Not that much of a coder to be able to appreciate the nuances here. yes I have used name == 'main' construct in python. It runs main. But I never understood why this convention.
 
4:12 PM
this is also very directly related to my earlier comment about how evaluating properly written declarations a second time does nothing at all
 
Like I have been a very careless programmer. I wouldn't ever go for __name__.. constructs. I will just put what I want to be executed at the end.
 
in Python, you want to be able to say import that_code to load the def and class and variable definitions etc but not yet run anything
 
Yes I still don't follow your earlier comment about how evaluating properly written declarations second time does nothing. I will brood over it.
I see. Makes sense now.
Yes I think I have the puzzle pieces with me to solve the .Xresources reload on the fly. I think I have to modify the github code so that when I eval-buffer it, the changes take place immediately.
 
so an Emacs mode definition declares functions and macros and default values for many variables, but the convention and expectation is that these defaults only get taken into use if the user hasn't already configured their own values for these
 
(I worry you may not approve of such quick-fix approaches)
Ohh....
It's been a very enlightening discussion. Thank you so much again.
 
4:18 PM
I'm not as dogmatic as I seem, I just want to make sure you are aware that there is a thing to watch out for and make a conscious decision
my pleasure, and good luck!
 
Yes, I am starting to get that feeling as well. :D
Will post you a copy of the solution (FYRP and code-review) if I am able to make it work! Hack-and-slash ;)
 
thanks - now I'm off to put kids to bed
 

  last day (25 days later) »