AutoLisp - Prompt User Save As Text File - lisp

I'm trying to write some code to prompt the user on where to save a document. I've run across getfiled, which prompts for the user to open an exsisting file, but I'm not finding a command that will show a window as seen below.

Well, the answer is a bit more obvious than anticipated. The last argument that can be passed into getfiled will change the File Explorer from "Open" to "Save As."
;; Opens exsisting file
(getfiled "Title" "test.txt" "" 0)
;; Saves file
(getfiled "Title" "test.txt" "" 1)
Reference 1: help.solidworks.com
Reference 2: help.autodesk.com
Reference 3: docs.autodesk.com

Related

Org Capture: prompt for information when determining the target file

I'm looking to build a capture template that, when run, prompts the user for more information to determine the path of the target file.
I have a few pieces already.
A function which asks the user for data and returns a string:
(defun my/get-121-orgfile ()
"Ask the user for the name of the participant so that we can build"
(interactive)
(read-string "Participant Name: ")
)
An org-capture-template which will run the prompt successfully when emacs loads:
(setq org-capture-templates
`(
("m1" "1-1 meetings")
("m1b" "prep for a 1-1 meeting" entry
(file ,(concat "~/org/meetings/1-2-1/" (my/get-121-orgfile) ".org"))
(file "~/org/templates/meeting-121-prep.org")
:clock-in t)
))
I took the back quote and comma pattern from this SO answer, but I haven't been able to figure out how to scope this behaviour to when I select the template: I want the prompt to pop up each time I hit <org-capture>m1b.
The backquote-comma pattern will not help here: it will call the function at the time that org-capture-template is set. What you are trying to do is to call the function when the capture is executed.
The only way I know to do that would to use the (function foo) target mechanism of org-capture-templates. The doc string says:
(function function-finding-location)
Most general way: write your own function which both visits
the file and moves point to the right location
So you would not be able to use the (file ...) target as you do above. Instead you have to write a function that gets all the information you want and then visit the target file at the target location and add the filled-out template.
This is not a complete answer but it was too long for a comment, but maybe it helps to point you in the right direction.

Copy history of commands in matlab

I know how to save variables in matlab by this command
save
and load it by this command
load
but the question how to copy history of commands in txt file
save won't save commands, it saves the variables in your current workspace.
MATLAB history is saved in a History.xml file, the directory can be viewed by prefdir command.
For plain .txt command, just press up-arrow, and select-all from the history small list, copy it to whatever place you want. You may find this documentation helpful.
Just in case you do not have access to the admin folders or don't have required previleges,here's a simple method that worked for me,accidentally.
Go to the command prompt
and press CNTRL+A (Select All) and then CNTRL+C(Copy)
You will be prompted that :
It is not possible to show 13xx commands on the screen,
Go ahead anyway.
Then simply CNTRL + V (Paste) everything in any text editor.
Voila!
Hope it helps,
Anuj

emacs bookmark+ :How to create a file specific bookmark file?

bookmark+ package provides a (bmkp-this-file-bmenu-list) function. This, I suppose, loads a file specific bookmark file and filters only the bookmarks, which relate to the file.
Question: how to create this specific bookmark file for a specific file?
The result should be a filtered list of bookmarks, when using C-x p , command (which is bound to (bmkp-this-file-bmenu-list)
).
Edit: I use only one default bookmark file ~/.emacs.d/bookmarks. This file has some bookmarks for ~/.emacs file. Now, when I visit, say, ~/.emacs file, then run C-x p ,, I get the following error: bmkp-this-file-bmenu-list: No bookmarks for file ~/.emacs.
No, actually, command bmkp-this-file-bmenu-list does this (from the doc string):
Show the bookmark list just for bookmarks for the current file.
Set `bmkp-last-specific-file` to the current file name.
If the current buffer is not visiting a file, prompt for the file name.
It shows the *Bookmark List* display, listing only and all bookmarks that target the current file.
So if you use this command in a file buffer then you see displayed, in buffer *Bookmark List*, all of the bookmarks to the current file, and only those bookmarks.
This has nothing to do with using a different bookmark file.
Beyond what this command does, it's not clear to me what behavior you would like. What, for instance, do you mean by a "specific bookmark file for a specific file"?
You can create a different bookmark file using bookmark+ with M-x bookmark-load. You will be prompted for a filename. You can either merge bookmarks from different files or replace the current bookmark set entirely with this fileset by supplying a prefix argument.
Saving bookmarks bookmark-save will write all current bookmarks to the current value of the variable bmkp-current-bookmark-file , or if you supply a prefix arg you can choose a bookmark filename to save them to.
If you want a set of bookmarks in a distinct file, associated with particular files you could perhaps achieve this by running bookmark-load , and bookmark-save with prefixes. You could probably even automate this with hooks to match your editing contexts, although I expect that would be a little fiddly to achieve.
It sounds like your question might be rooted in some confusion about existing bookmark behaviour, and perhaps you don't even need to maintain separate bookmark files.

editing objects from MongoDB with an external editor doesn't update the object

I'm using the Mongo shell. I've set my EDITOR to my notepad++ path. I create an object and then I use the EDIT command to edit the obeject using notepad++ but it doesn't update the object.
// mongo shell
var pow = { name: "teest" };
edit pow
// notepad++ opens a document called 'mongo_edit141225123.js' that resides
// in C:\users\...\Appdata\local\temp
// I edit the object, save and close notepad++
pow // object isn't updated :(
what am I missing?
There seem to be a few caveats here. But I can describe how I got this working:
Set the PATH environment variable to include the path to the notepad++ executable. Note to both "apply" this change and not have an existing command line window when doing so. Or at least open a new one once this step is complete.
Specify an EDITOR variable in your command shell window, or otherwise set that under the same system properties as setting the PATH environment variable. Since the program directory is in the PATH just set the executable name:
set EDITOR="notepad++"
Launch your mongo shell and go to edit a variable:
> edit something
This will launch the specified editor, with an "undefined" variable at first. Type in something "valid", as any invalid JavaScript declaration will be discarded. Now for the important part. After your edit and when "closing" click the "tab close" icon and do not close the entire editor as shown:
That last part seems to be the most important. If you are prompted to save (and you likely will be ) then do so. Only "after" the tab has been closed (and saved) should you then close the editor itself.
If you then subsequently issue the same edit something from the mongo shell, then the editor will open with the content that you edited before.
If you don't follow this and just close the editor window first, then you should see an additional tab opened and the original tab with the content that you had before. But subsequent changes will be lost as the shell is now tracking a different temporary file.
So follow those steps and you should be right. I would expect there are similar issues with other external editors that will actually resolve in a similar way.

How to view content of emacs autosave file

How do I directly see the content of an emacs autosave file, without implementing a file recovery operation?
That is, suppose I created a file with 'emacs foo', then emacs crashed, so I'm left with no file named 'foo' (since it never was saved) but with a file '#foo#'. When I type 'more #foo#', I get "Missing filename", as though the more command doesn't even see the #foo# part of the command.
I just want to see the text in #foo# so I can copy it out by hand without risking something going wrong in the file recovery process (eg #foo# getting overwritten by a new autosave operation).
(I'm using Terminal on OSX.)
Bash or another shell use '#' as comment character, try :
more "#foo#"