[Top][All Lists]

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

Re: How to use project.el

From: excalamus
Subject: Re: How to use project.el
Date: Sat, 21 Nov 2020 02:03:13 +0100 (CET)

> To get the most benefit from the package, you should install the latest 
> version from GNU ELPA ('M-x list-packages', then install 'project'). The 
> latest version is 0.5.2.
> To see the full list of commands defined in that package, type 'C-x p C-h'.
> You can also read the full description of the package with 'C-h P project 
> RET'.
Thank you, I was unfamiliar with 'C-h P'.

I have updated to 0.5.2 and it's more like what I would have expected.  
Actually, several functions mirror my own project management code.  My use-case 
is, of course, specific to me, but I see overlap.  I wonder if any of my code, 
or its ideas, may be useful?  Who is project.el's point person?

 I develop Python and prefer to interact through shell directly by sending 
commands to the comint buffer.   At this point the main command is 
'xc/sh-send-command'.  This sends something like 'python' or 
'pyinstaller main.spec' to the appropriate shell and steps.  I create a shell, 
either by name or on the fly, similar to 'project-shell' with 
'xc/create-shell'.  Everything else is just a helper.  

It's all hacky stuff I've made in the moment over time.  This weekend, I hoped 
to create project profiles, a plist or something, with :root, :venv, 
:entry-point-file, etc., so that I can switch between shells and associated 
command sets easily, maybe also formalize it (hence my looking into project.el 


(defun xc/set-global-default-directory (new-default-directory)
  "Set xc/global-default-directory to NEW-DEFAULT-DIRECTORY."
  (interactive "DSet global default directory: ")
  (setq xc/global-default-directory new-default-directory))

(defvar xc/python nil
  "Python interpreter to be used in shell calls.")

(defvar xc/shell "*shell*"
  "Shell process buffer to be used in shell calls.")

(defun xc/set-python (exe)
  "Set python executable."
   (list (read-file-name "Python executable: " 
"C:/Users/excalamus/Anaconda3/envs/" nil t)))
  (setq xc/python (concat exe " "))
  (message "Set `xc/python' to: %s" xc/python))

(defun xc/set-shell (pbuff)
  "Set `xc/shell' to process associated with PBUFF buffer."
   (list (read-buffer "Process buffer: " nil t '(lambda (x) (processp 
(get-buffer-process (car x)))))))
  (setq xc/shell pbuff)
  (message "Set `xc/shell' to: %s" xc/shell))

(defun xc/create-shell (name)
    "Create shell with a given NAME.

NAME should have earmuffs (e.g. *NAME*) if it is to follow Emacs
naming conventions.  Earmuffs indicate that the buffer is special
use and not associated with a file.

Returns newly created shell process.

Adapted from URL `'"
     (let ((name (read-string "shell name: " nil)))
       (list name)))
    (let ((name (or name xc/shell)))
      (get-buffer-process (shell name))))

(defun xc/sh-send-command (command &optional pbuff)
  "Send COMMAND to shell process with buffer PBUFF.

PBUFF is the buffer name string of a process.  If the process
associated with PBUFF does not exist, it is created.  PBUFF is
then opened in the other window and control is returned to the
calling buffer.

See URL `'"
  (let* ((pbuff (or pbuff xc/shell))
         (proc (or (get-buffer-process pbuff)
                   ;; create new process
                   (let ((currbuff (current-buffer))
                         (new-proc (xc/create-shell pbuff)))  ; creates a 
buried pbuff
                     (switch-to-buffer-other-window pbuff)
                     (switch-to-buffer currbuff)
         (command-and-go (concat command "\n")))
    (with-current-buffer pbuff
      (goto-char (process-mark proc))
      (insert command-and-go)
      (move-marker (process-mark proc) (point)))
    (process-send-string proc command-and-go)))

(defun xc/set-global-shell-command (new-command)
  "Set `xc/global-shell-command' to NEW-COMMAND."
  (interactive "sShell command: ")
  (setq xc/global-shell-command new-command))

;; todo make interactive, read envs dir for available envs, send to shell, etc.
(defun xc/conda-activate ()
  "Activate conda venv."
  (insert "C:\\Users\\excalamus\\Anaconda3\\condabin\\conda.bat activate "))

(defun xc/set-global-shell-command-to-current-file ()
  "Set the global shell command to use the current file.

This is useful if, for instance, a project was started using one
file, but later in development another file needs to be called
frequently.  It is like a permanent version of
  (setq xc/global-shell-command (concat xc/python (buffer-file-name)))
  (message "Set `xc/global-shell-command' to \"%s\"" xc/global-shell-command))

(defun xc/buffer-file-to-shell ()
  "Send current buffer file to shell as python call."
  (let ((script (buffer-file-name)))
    (if script
        (xc/sh-send-command (concat xc/python script))
      (error "Command not sent. Buffer not visiting file"))))

reply via email to

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