{"action":"created","issue":{"url":"https://api.github.com/repos/lewang/ws-butler/issues/14","labels_url":"https://api.github.com/repos/lewang/ws-butler/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/lewang/ws-butler/issues/14/comments","events_url":"https://api.github.com/repos/lewang/ws-butler/issues/14/events","html_url":"https://github.com/lewang/ws-butler/issues/14","id":55197444,"number":14,"title":"ws-butler with desktop-save-mode and emacs --daemon","user":{"login":"anirothan","id":786183,"avatar_url":"https://avatars.githubusercontent.com/u/786183?v=3","gravatar_id":"","url":"https://api.github.com/users/anirothan","html_url":"https://github.com/anirothan","followers_url":"https://api.github.com/users/anirothan/followers","following_url":"https://api.github.com/users/anirothan/following{/other_user}","gists_url":"https://api.github.com/users/anirothan/gists{/gist_id}","starred_url":"https://api.github.com/users/anirothan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anirothan/subscriptions","organizations_url":"https://api.github.com/users/anirothan/orgs","repos_url":"https://api.github.com/users/anirothan/repos","events_url":"https://api.github.com/users/anirothan/events{/privacy}","received_events_url":"https://api.github.com/users/anirothan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-22T19:29:38Z","updated_at":"2015-01-26T15:26:37Z","closed_at":"2015-01-26T15:26:37Z","body":"The combination of using emacs daemon, with desktop-saved buffers that had ws-butler minor mode enabled causes the emacs daemon to hang when trying to restore these buffers.\r\n\r\nThis is related to issues: https://github.com/lewang/ws-butler/issues/12 and https://github.com/lewang/ws-butler/issues/4\r\nbut none offered a solution for me. \r\n\r\nI have manage to create a workaround by doing two things:\r\n\r\ni) Configure desktop-save-mode to ignore ws-butler mode and the highlight-changes-mode that it is based on.\r\n\r\n````elisp\r\n;;\r\n;; enable desktop-save\r\n(desktop-save-mode t)\r\n;;\r\n;; disable saving/reloading of ws-butler-mode and highlight-changes\r\n(delete 'highlight-changes-mode desktop-minor-mode-handlers)\r\n(add-to-list 'desktop-minor-mode-handlers '(highlight-changes-mode . nil) t)\r\n(add-to-list 'desktop-minor-mode-handlers '(ws-butler-mode . nil) t)\r\n(add-to-list 'desktop-minor-mode-table '(highlight-changes-mode nil) t)\r\n(add-to-list 'desktop-minor-mode-table '(ws-butler-mode nil) t)\r\n````\r\n\r\nThis is not enough. Enabling ws-butler-global-mode or using hooks of other modes to enable ws-butler in the standard way sill causes the emacs daemon to hang on startup.\r\n\r\nii). Enable ws-butler-mode in the after-make-frame-functions hook. If you want ws-butler-mode enabled globally then this is easy:\r\n\r\n````elisp\r\n(defun jd/enable-ws-butler-global (frame)\r\n  (ws-butler-global-mode))\r\n(add-hook 'after-make-frame-functions 'jd/enable-ws-butler-global)\r\n````\r\nThis will enable ws-butler eveywhere every time a new frame is created.\r\n\r\nHowever, if you want ws-butler to be enabled for certain modes via mode-hooks, say just for c-mode, then it's tricky. The related files, e.g. of c-mode, are already loaded on daemon startup by dekstop-save-mode and their hooks have already executed. To get around this, we need to register the hooks and revert all buffers (that have a file) only on the first created frame.\r\n\r\n````elisp\r\n;;\r\n;; ws-buttler setup\r\n(defun jd/setup-ws-butler-hooks ()\r\n  \"Register hooks to enable ws-buttler\"\r\n  (require 'ws-butler)\r\n  (add-hook 'prog-mode-hook 'ws-butler-mode)\r\n  (add-hook 'c-mode-common-hook 'ws-butler-mode)\r\n  (add-hook 'text-mode 'ws-butler-mode)\r\n  (add-hook 'fundamental-mode 'ws-butler-mode))\r\n;;\r\n;; workaround on ws-butler inhibit emacs daemon startup\r\n(setq jd/frame-rendered-flag nil)\r\n;;\r\n;; revert buffers in frame so that hooks re-run\r\n(defun jd/revert-buffers-in-frame-and-reload-modes (frame)\r\n  \"Refreshes all open buffers from their respective files in the given frame, reloading any modes.\"\r\n  (dolist (buf (buffer-list frame))\r\n    (with-current-buffer buf\r\n      (when (and (buffer-file-name) (file-exists-p (buffer-file-name)) (not (buffer-modified-p)))\r\n        (revert-buffer t t nil)\r\n        (message \"Reloading file %s\" (buffer-file-name))))))\r\n;;\r\n;; if flag not set, register hooks for ws-butler, revert buffers\r\n(defun jd/enable-ws-butler (frame)\r\n  (unless jd/frame-rendered-flag\r\n    (jd/setup-ws-butler-hooks)\r\n    (jd/revert-buffers-in-frame-and-reload-modes frame)\r\n    (setq jd/frame-rendered-flag t))) \r\n\r\n(add-hook 'after-make-frame-functions 'jd/enable-ws-butler)\r\n````\r\n\r\nIt seems to me that, the problem of using ws-butler with emacs --daemon and desktop-save-mode is due to ws-buttler or one of its dependencies really really wanting X11 to be present, which at the startup of emacs --daemon is not. This means we have to go through all this pain to make it work.\r\n\r\nCan the developers investigate if the issue is due to ws-butler and fix it, or point to suspected dependecy packages, e.g. highlight-changes-mode?"},"comment":{"url":"https://api.github.com/repos/lewang/ws-butler/issues/comments/71477502","html_url":"https://github.com/lewang/ws-butler/issues/14#issuecomment-71477502","issue_url":"https://api.github.com/repos/lewang/ws-butler/issues/14","id":71477502,"user":{"login":"lewang","id":586604,"avatar_url":"https://avatars.githubusercontent.com/u/586604?v=3","gravatar_id":"","url":"https://api.github.com/users/lewang","html_url":"https://github.com/lewang","followers_url":"https://api.github.com/users/lewang/followers","following_url":"https://api.github.com/users/lewang/following{/other_user}","gists_url":"https://api.github.com/users/lewang/gists{/gist_id}","starred_url":"https://api.github.com/users/lewang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewang/subscriptions","organizations_url":"https://api.github.com/users/lewang/orgs","repos_url":"https://api.github.com/users/lewang/repos","events_url":"https://api.github.com/users/lewang/events{/privacy}","received_events_url":"https://api.github.com/users/lewang/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T15:26:37Z","updated_at":"2015-01-26T15:26:37Z","body":"No.  In fact (hopefully) there is a gain of functionality - it now works better with killing+undo.\r\n\r\nI started piggybacking on highlight-changes as a proof of concept, and it turned out to be good enough for the common case.  This is a better implementation .\r\n\r\nClosing now."}}