[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: And while we're at it...
From: |
Tassilo Horn |
Subject: |
Re: And while we're at it... |
Date: |
Wed, 01 Dec 2010 17:19:36 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
Gary <help-gnu-emacs@garydjones.name> writes:
> Yeah, I'd read and mentally noted that. What I'm missing is how to
> goto-buffer-position-where-text-should-be-inserted, as you put it. I
> found backward-line which might help, but I don't know what position
> in that line the "point" would then be. End? Beginning? Somewhere in
> the middle?
No, don't use that in lisp code. Instead use `forward-line' with a
negative argument:
,----[ C-h f forward-line RET ]
| forward-line is an interactive built-in function in `C source code'.
|
| (forward-line &optional N)
|
| Move N lines forward (backward if N is negative).
| Precisely, if point is on line I, move to the start of line I + N
| ("start of line" in the logical order).
| If there isn't room, go as far as possible (no error).
| Returns the count of lines left to move. If moving forward,
| that is N - number of lines moved; if backward, N + number moved.
| With positive N, a non-empty line at the end counts as one line
| successfully moved (for the return value).
`----
> The code I am writing is designed to act on text like this:
> ,----
> | foo somethinghere
> | ...
> | end
> `----
>
> And here it is, somewhat simplified:
> ,----
> | (defun my-fn ()
> | (interactive)
> |
> | ;; get the components of the current line
> | (setq myStr (thing-at-point 'line))
> | (setq myLineComponents (split-string myStr " "))
Don't use `setq' for local vars, use `let'.
> | ;; get the type of "thing" on this line
> | (setq mySemanticObj (pop myLineComponents))
> |
> | ;; ..and based on that, insert something appropriate
> | (if (equal mySemanticObj "foo")
Don't use `equal' but `string=' when comparing strings.
> | (progn
> | (backward-line 1) ;; hmm! where in the line do i end up?!?
Use (forward-line -1) and you'll end up in column zero of the previous
line.
HTH,
Tassilo
- Re: And while we're at it..., Tassilo Horn, 2010/12/01
- Message not available
- Re: And while we're at it...,
Tassilo Horn <=
- Message not available