0

Currently I am using the function workbench. The function workbench-named introduces a name, which I want to include in buffer and file-name.

Currently only workbench-prefix in being included with the command

(buffer (or name (concat "*" workbench-prefix "*")))

For instance

  1. I want the buffer name to be "*Arktika-<name>*", where name is
    supplied by the user when calling workbench-named.
  2. When saving the buffer to a file, I construct a path followed by the time, then appending "-Arktika-" if name was supplied
  3. When using prefix with C-u M-x workbench, I am asked to supply a major-mode.

Here is the implementation

    (defvar workbench-prefix "Arktika")
    (defvar workbench-dtrek "~/wb/")
    (defvar workbench-histr nil)
    (defvar workbench-modes
      '( ("emacs-lisp-mode" . "el")
         ("lisp-mode" . "lisp")
         ("org-mode" . "org") ))
   
    (defun workbench (&optional prefix name mode)
      "Generate new temporary buffer."
      (interactive "p")
      (let* ( (buffer (or name (concat "*" workbench-prefix "*")))
              (file-name
                 (concat workbench-dtrek
                         (format-time-string "%Y-%m-%d-T%H:%M:%S--")
                         workbench-prefix "-" name ".org")) )
      (switch-to-buffer (generate-new-buffer buffer))
        (setq buffer-file-name file-name)

    (if current-prefix-arg
        (let* ( (mode (completing-read " Mode: "
                        (map-keys workbench-modes) nil t nil
                        'workbench-histr)) )
          ;; with prefix-arg, use user defined mode
          (funcall (intern mode)))
      ;; otherwise use org-mode
      (funcall (intern (or mode "org-mode"))))

        buffer-file-name))
    
    (defun workbench-named ()
      "Generate new temporary buffer by asking for buffer name."
      (interactive)
      (workbench (read-from-minibuffer " Workbench Name: ")))
3
  • 1
    Please be more specific. This shows a bunch of code and asks a vague question that amounts to "How can I code what I want (which isn't specified)?" And you didn't even check that the code is syntactically correct (missing " at end of doc string).
    – Drew
    Jun 29 at 14:00
  • I cannot see where I am missing ".
    – Ephram
    Jun 29 at 14:08
  • You can't see it because I added the missing ". Look at the edit history.
    – Drew
    Jun 29 at 15:25

1 Answer 1

0

Where are you expecting optional parameter name to be provided?

If you invoke the command interactively then name is nil, because your interactive spec doesn't give it a non-nil value.

Since name is nil, your binding for buffer gets the second value passed to or, which is (concat "*" workbench-prefix "*"). That's why you're seeing only the value of workbench-prefix, wrapped in *.

And in your question you don't specify any interactive behavior you might want for name. Maybe you want something like this?

(interactive "p\ns")

Beyond that, you pass the numeric prefix arg (which is 1 by default) as parameter prefix, and you never even use prefix in your code!

Maybe you want to remove parameter prefix and use only name? Maybe you want to use s and not p in the interactive spec?

It's impossible to guess what you're really wanting to do, so it's unlikely to be able to guess what answer might help you. (Please try to pose clearer questions.)

5
  • I only put it so I can use (if current-prefix-arg. Prefix is used to activate completing-read so that I can select a major-mode for the buffer. It would help on simplifying the implementation.
    – Ephram
    Jun 29 at 16:10
  • No idea what you're saying. You don't use current-prefix-arg in your code. And as I said, arg prefix is unused (and is 1, the numeric prefix value). And arg name is useless in your code: it's always nil and that's ignored by concat.
    – Drew
    Jun 29 at 20:27
  • I added tho part that uses current-prefix-arg. You see a better way to set the mode? Cannot see how the arg name in not used when calling workbench-named.
    – Ephram
    Jun 29 at 20:40
  • No idea what you're doing, sorry. Your code doesn't ever bind or set argument name, so it's always nil (default for an optional arg). And your code doesn't make use of function workbench-named.
    – Drew
    Jun 29 at 21:35
  • Am just making named buffer using a major mode. Which I can save with a filename that includes the date.
    – Ephram
    Jun 29 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.