emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Neat features in Eclipse editor


From: paul r
Subject: Re: Neat features in Eclipse editor
Date: Mon, 24 Mar 2008 19:47:54 +0100

2008/3/24, Richard Stallman <address@hidden>:

>  Likewise, changes you make in the layout of a perspective permanently
>  alter that perspective.  The changes persist between sessions too.
>
>  There are also several initially defined perspectives that are useful
>  for specific purposes.
>
>  What we have now is a bare-bones feature that isn't really useful.
>  Perspectives are a convenient feature that really is useful.
>  Perhaps there is no "fundamental" difference, but the UI difference
>  is all the difference in the world.
>

In case of interest, you can find below a very simple package that
does basically that.
As I tend to use it intensively, I made it so that this operation
requires minimal keystrokes.
A workspace is a windows configuration.
Each workspace is bound to a key. Any char is acceptable for it. So
use 'm' for mail, 'e' for elisp, d for documentation ... well up to
you.
Workspace-goto is bound on C-c C-d by default. A key must follow.
- Backspace kills current workspace.
- Tab shows workspaces list.
- Space swaps workspaces forth and back.
- Enter restore current workspace.
- Any other key creates this 'key' workspace
You might notice that, in order to reduce the noise generated by
global functions and global bindings, only variables and functions
that constitute the interface are accessible. The rest is enclosed in
a closure. This closure currently makes use of CL lexical facilities.
We talked a bit about that in the recent "lexbind" thread.
You can safely try it, it's easy to use.


;; DEFINITION
;;-----------
;;
;; Multi-workspaces
;; Author : Paul Rivier <paul dot r dot ml at gmail dot com>
;;
;; Load this file, then use C-c C-d [any character] to switch to
workspace specified
;; Special keys are :
;;  - TAB to show workspaces list
;;  - space to swap with last workspace
;;  - DEL to kill current workspace
;;  - RET to restore current workspace to its saved state


;;;;;;;;;;;;;;;;;;
;; DEPENDENCIES ;;
;;;;;;;;;;;;;;;;;;
(eval-when-compile (require 'cl))

;;;;;;;;;;;;;;;
;; VARIABLES ;;
;;;;;;;;;;;;;;;

(defvar current-workspace nil "Workspace you are currently in")
(defvar default-workspace ?1
  "This workspace will be created at init time. You can not delete
this workspace. When killing a workspace, you fallback to
default-workspace.")
(defvar workspaces-list nil "List of open workspaces")

;;;;;;;;;;;;;;;;;;;;;
;; GLOBAL BINDINGS ;;
;;;;;;;;;;;;;;;;;;;;;

(global-set-key "\C-c\C-d" 'workspace-goto)

;;;;;;;;;;;;;;;
;; FUNCTIONS ;;
;;;;;;;;;;;;;;;
(lexical-let ((last-workspace default-workspace))
  ;; above : vars -- below : functions
  (labels ((workspaces-list-sort
            ()
            ;;      "Sort list workspaces-list, save and return it."
            (setq workspaces-list
                  (sort workspaces-list
                        (lambda (a b)
                          (< (car a) (car b))))))
        
           (workspaces-list-add
            (wsid)
            ;;      "Add current configuration to workspaces list under wsid."
            (setq workspaces-list
                  (cons
                   (cons wsid (current-window-configuration))
                   workspaces-list))
            (workspaces-list-sort))
        
           (workspace-save-current
            ()
            ;;      "Save current workspace."
            (workspace-delete current-workspace)
            (workspaces-list-add current-workspace))
        
           (workspace-delete
            (wsid)
            ;;      "Delete workspace wsid."
            (setq workspaces-list
                  (assq-delete-all wsid workspaces-list)))
        
           (workspaces-id-list
            ()
            ;;      "Return a list of workspaces ids."
            (mapcar #'car workspaces-list))
        
           (workspace-create-new
            (wsid)
            ;;      "Create a new workspace with id wsid."
            (workspace-goto ?0)
            (workspaces-list-add wsid)
            (workspace-goto wsid))
        
           (workspace-kill-current
            ()
            ;;          "kill the workspace you are currently in"
            (if (not (or (eq current-workspace default-workspace)
                         (eq current-workspace ?0)))
                (let ((cws current-workspace)
                      (lws last-workspace))
                  (workspace-goto default-workspace)
                  (workspace-delete cws)
                  (setq last-workspace default-workspace)
                  (concat "\nWorkspace "
                          (char-to-string cws) " killed"))
              (concat "\nSpecial workspaces "
                      (char-to-string current-workspace)
                      " can not be killed")))
        
           (workspace-exists-p
            (wsid)
            ;;      "Return t if workspace wsid exists."
            (when (assoc wsid workspaces-list) t)))

    ;; externaly bound functions

    (defun workspaces-init ()
      "Initialize workspaces-list and others"
      (setq workspaces-list nil)
      (workspaces-list-add ?0)
      (setq current-workspace ?0)
      (workspace-goto-or-create default-workspace))

    (defun workspace-goto-or-create (wsid)
      "If workspace wsid exists, goto it, else create it."
      (if (workspace-exists-p wsid)
          (workspace-goto wsid)
        (workspace-create-new wsid)))

    (defun workspace-goto (wsid)
      "Go to another workspace, wsid is workspace identifier. wsid
can be any character, except those mentioned below. Workspace 0
is a template workspace, do not use it unless you know what you
do. Hit TAB to have workspaces list. You can kill a workspace
with 'k', you will fallback on default workspace."
      (interactive "cTo which workspace do you want to go ? ")
      (let ((wscfgcons (assoc wsid workspaces-list))
            (special ""))
        (if wscfgcons
            (progn
              (unless (eq wsid current-workspace)
                  (workspace-save-current))
              (set-window-configuration (cdr wscfgcons))
              (unless (or (eq current-workspace ?0)
                          (eq wsid current-workspace))
                (setq last-workspace current-workspace))
              (setq current-workspace wsid)
              (when (eq wsid ?0)
                (setq special
                      "\n!-!-! This is template workspace. New workspaces are 
based on it.")))
          ;; Workspace does not exist, it might be a special key
          (cond
           ((eq wsid 9) ; 9 is TAB
            ())
           ((eq wsid 13) ; 13 is RET
            (workspace-goto current-workspace)
            (workspace-save-current))
           ((eq wsid 32) ; 32 is space
            (workspace-goto last-workspace))
           ((eq wsid 127) ; 127 is DEL (backspace)
            (setq special (workspace-kill-current)))
           ;; it is not a special key, create workspace
           (t
            (when (y-or-n-p
                   "This workspace does not exist, should it be created ? ")
              (workspace-create-new wsid)))))
        (message (concat "Now on workspace " (char-to-string current-workspace)
                         "\nWorkspaces list is : "
                         (mapconcat 'char-to-string
                                    (remq ?0 (workspaces-id-list)) "  ")
                         special))))
    ))

;;;;;;;;;;;
;; HOOKS ;;
;;;;;;;;;;;
;; base workspaces 0 and default are created at startup only

(unless workspaces-list (workspaces-init))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]