Elisp performance on Windows and Linux - performance

I have the following dead simple elisp functions; the first removes the fill breaks from the current paragraph, and the second loops through the current document applying the first to each paragraph in turn, in effect removing all single line-breaks from the document. It runs fast on my low-spec Puppy Linux box using emacs 22.3 (10 seconds for 600 pages of Thomas Aquinas), but when I go to a powerful Windows XP machine with emacs 21.3, it takes almost an hour to do the same document. What can I do to make it run as well on the Windows machine with emacs 21.3?
(defun remove-line-breaks ()
"Remove line endings in a paragraph."
(interactive)
(let ((fill-column 90002000))
(fill-paragraph nil)))
:
(defun remove-all-line-breaks ()
"Remove all single line-breaks in a document"
(interactive)
(while (not (= (point) (buffer-end 1)))
(remove-line-breaks)
(next-line 1)))
Forgive my poor elisp; I'm having great fun learning Lisp and starting to use the power of emacs, but I'm new to it yet.

As the first try, you should download and install Emacs 22.3 for your Windows box and then compare the speed.
Speed difference shouldn't be that big after upgrade.

Perhaps it is the big value you assign to fill-column (they suggest less than 80).

Related

Delphi 7 Line Indentation option?

I have received 10 PAS files. All the lines in these 10 files starts in column 1. NO indentation at all.
Biggest file is 2548 lines.
Now I wonder: Is there an OPTION in my Delphi 7 Enterprise (running on XP sp 3) to automate that indentation to increase readability (at least for me):
IF not I plan to scan through the files and when BEGIN, THEN, ELSE, CASE, END etc. (where indentation will be natural) is met, I will (if necessary) do a manually indentation. (But it is smarter letting Delphi do it).
you can use CnPack
http://www.cnpack.org/showlist.php?id=39&lang=en
it has (among a lot of features) a Code Formatting Wizard and some other nifty features to enchance the IDE

losing text while pasting into vi

I'm running into some trouble using Vim in OSX which is: whenever I copy outside of Vim and COMMAND + P to paste text inside, a few characters of the copied text gets deleted.
COPY: Function(){...... + 20 lines
PASTE n(){..... + 20 lines)
I know Vim has a lot of ins and outs... I use it without trouble on my Ubuntu setup. But I am not really expert with it yet and I have a feeling this is a basic issue mac users will have encountered. However, I was looking through the forums and googling it, and I cannot seem to find an answer.
Appreciate so much any help.
EDIT: I know this is a very basic question that someone might ask if they didn't understand the basics of Vi insert mode and hadn't like run Vimtutor. For me that was not quite the issue; I actually have been working of Vim for a while, but this default behavior had been changed early on (so I never noticed it).
I definitely would have wasted a lot of time before considering the basics of how insert mode works, so really thank you so much for your awesome, timely responses! I hope that this thread is useful to some other folks who're perhaps inadvisably pulled some "boilerplate" .vimrc off the internet, or have gotten used to Vim as configured by others... because the point of Stack Overflow isn't to explain to people things they should have picked in like 10 seconds from a man page or whatever.
It looks like you're not in insert mode when you're pasting, so Vim interprets the text as commands, until one letter (e.g. i or o) accidentally switches to insert mode. [1]
You need to go into insert mode first (i, also consider :set paste, and the 'pastetoggle' option; :help 'paste' has some background information).
Or (when supported), access the clipboard from within Vim, e.g. via "+p (normal mode) or <C-R><C-R>+ (insert mode).
As only the terminal-based versions of Vim have this problem of differentiating between typed and pasted keys, switching to the GUI GVIM (I think called MacVim there) would avoid this problem, too.
[1] Vim understands the example as:
Fu: backward find character u
n: next search match
cti: change until before the next character i (which aborts insert mode when there's no such character)
o: new line below the cursor and insert text

Emacs: How to improve ido performance?

I found that if the ido completion list contains hundreds of items, it would be too slow to give completion suggestions.
I want to make use of ido's ability with high response speed. Any suggestions about how to fix the problem?
I use ido to complete Unicode character names, of which there are upwards of 30,000. Ido was quite slow until I set ido-enable-flex-matching to nil for this single operation, and it immediately became essentially as fast as for any other matching operation. Maybe this tactic can help you, too.
In a nutshell, I did this:
(let* ((ido-enable-flex-matching nil)
(input (ido-completing-read prompt (ucs-names))))
; ...
)

Sending a keystroke to the operating system in EmacsW32

As you probably know if you write text in multiple languages and use Emacs, Emacs has its own input method system independent of Windows (or other operating systems). Input methods can be toggled with toggle-input-method command. When Windows language changes, Emacs receives a <language-change> keypress. I would like then to bind <language-change> to toggle-input-method. Unfortunately, if I do just
(global-set-key (kbd "<language-change>") 'toggle-input-method)
both Windows language and input method will be toggled. So I need something like
(defvar safe-language-change-flag nil)
(defun safe-language-change ()
(interactive)
(setq safe-language-change-flag (not safe-language-change-flag))
(when safe-language-change-flag
(toggle-input-method)
(send-key (kbd "<language-change>"))))
(global-set-key (kbd "<language-change>") 'safe-language-change)
What I can't seem to find is a function call which would send a key to the operating system (or change the system language in another way).
Just to make sure, you want this to happen: You change the language in the OS. Emacs gets this event, sends a keypress back to the OS, and then un-changes the language.
You may be able to call an external utility to do this.
I'm not sure why you want to do this, though.
If you've changed the OS's language, then let the OS handle the input method. If you don't want to use your OS's input method, then do toggle-input-method inside emacs, and don't bother worrying about the OS's state.
Am I missing something?
If you don't want to use your OS's input method, then do toggle-input-method inside emacs, and don't bother worrying about the OS's state.
This is precisely the result I want to get. The difficulty is that I find myself switching the OS input method instead all the time because "press Shift to switch language" is a part of my finger memory by now.

How do I get a terminal program to honour cursor keys?

I'm using ccl/openmcl on Mac OS X. (latest versions of both). When the lisp prompt is displayed, using the cursor keys to navigate the current line results in escape codes, rather than movement, eg:
Welcome to Clozure Common Lisp Version 1.2-r9226-RC1 (DarwinX8664)!
? (^[[D
Here I've pressed the ( key, and then the left cursor key.
When I run ccl/openmcl on a Debian Etch box, the cursor behaves as expected, and moves the insert point one position left.
I guess this is some sort of terminal configuration option?
If Clozure CL doesn't provide native readline/editline/whatever support or is configured not to use it, you can run it with rlwrap, for example:
rlwrap openmcl
rlwrap can be obtained via MacPorts or directly from http://utopia.knoware.nl/~hlub/rlwrap/.
i know that i'm not answering the question with this, but you should not spend much time directly using a lisp repl.
using emacs and slime is a much more convenient way of interacting with a lisp. you have an inspector and a debugger at hand, you can jump to the source code of the functions, etc.

Resources