Skip to content

Commit

Permalink
support ivy-occur-grep-mode; refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Bin committed Dec 18, 2021
1 parent 691298a commit b50a0f2
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 465 deletions.
27 changes: 18 additions & 9 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ If you want to set up this minor mode further:
(workgroups-mode 1) ; put this one at the bottom of .emacs
#+end_src
** Tips (OPTIONAL)
You can use =M-x customize-group workgroups= to see all variables and
faces to change.

*** Change workgroups session file
Use below code
#+begin_src elisp
;; Change workgroups session file
(setq wg-session-file "~/.emacs.d/.emacs_workgroups")
#+end_src

Hooks' names can tell when they are executed

*** Support some special buffer,
Here is minimum sample code to support =ivy-occur-grep-mode=,
#+begin_src elisp
wg-after-switch-to-workgroup-hook
(with-eval-after-load 'workgroups2
;; provide major mode, package to require, and functions
(wg-support 'ivy-occur-grep-mode 'ivy
`((serialize . ,(lambda (_buffer)
(list default-directory
(base64-encode-string (buffer-string) t))))
(deserialize . ,(lambda (buffer _vars)
(switch-to-buffer (wg-buf-name buffer))
(setq default-directory (nth 0 _vars))
(insert (base64-decode-string (nth 1 _vars)))
;; easier than `ivy-occur-grep-mode' to set up
(grep-mode)
;; need return current buffer at the end of function
(current-buffer))))))
#+end_src

** License
workgroups2 is free software: you can redistribute it and/or modify it under the terms of the [[https://github.com/raw/redguardtoo/workgroups2/master/LICENSE][GNU General Public License]] as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Expand Down
55 changes: 55 additions & 0 deletions src/workgroups2-sdk.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
;;; workgroups2-sdk.el --- sdk of workgroups2 -*- lexical-binding: t -*-

;; This file is NOT part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:
(require 'cl-lib)

(defvar wg-special-buffer-serdes-functions
'(wg-serialize-comint-buffer)
"Functions providing serialization/deserialization for complex buffers.
Use `wg-support' macro and this variable will be filled
automatically.
An entry should be either a function symbol or a lambda, and should
accept a single Emacs buffer object as an argument.
When a buffer is to be serialized, it is passed to each of these
functions in turn until one returns non-nil, or the list ends. A
return value of nil indicates that the function can't handle
buffers of that type. A non-nil return value indicates that it
can. The first non-nil return value becomes the buffer's special
serialization data. The return value should be a cons, with a
deserialization function (a function symbol or a lambda) as the car,
and any other serialization data as the cdr.
When it comes time to deserialize the buffer, the deserialization
function (the car of the cons mentioned above) is passed the
wg-buf object, from which it should restore the buffer. The
special serialization data itself can be accessed
with (cdr (wg-buf-special-data <wg-buf>)). The deserialization
function must return the restored Emacs buffer object.
See the definitions of the functions in this list for examples of
how to write your own.")

(provide 'workgroups2-sdk)
;;; workgroups2-sdk.el ends here
Loading

0 comments on commit b50a0f2

Please sign in to comment.