help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Determining existence of text following point


From: michael-franzese
Subject: Re: Determining existence of text following point
Date: Wed, 19 May 2021 10:05:30 +0200

Have made some simplifications to the code.  I would also like
to handle the following case.

;; ..........................................




> Sent: Wednesday, May 19, 2021 at 7:28 PM
> From: michael-franzese@gmx.com
> To: "Jean Louis" <bugs@gnu.support>
> Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" 
> <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Determining existence of text following point
>
> Point will always be at the beginning of a comment on a separate line
> 
> The "^" shows the position of the cursor.
> 
>                    ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
>          ^;; +++++++++++++++++++++++++++
> 
> ^;; ----------------------------
> 
> I want to have a keybinding that if I continue to hit will change
> a comment from
> 
> ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> to
> 
> ;; +++++++++++++++++++++++++++++++++++++
> 
> Currently I have the following code
> 
> 
> (defun insert-bifurcation (s n)
>    "todo"
> 
>    (let* ( (a (point))  (b (line-end-position))
>          (line-cut (buffer-substring-no-properties a b)) )
> 
>       (when (or (not (string-match
>                       "[^[:blank:]]" line-cut)) (eolp))
>          (pcase n
> 
>           (0
>               (save-excursion (insert s))
>               (comment-region a b))
>           
>           ((or 1 2 3 4 5)
>               (delete-region a b)
>               (save-excursion (insert s))
>               (comment-region a b))
> 
>             (_
>               (delete-region a b))) )) )
> 
> (defvar count 1)
> 
> (defun insert-bifurcating-comment ()
>   "Insert bifurcating line at cursor position"
>   (interactive)
> 
>   (let* ( (m 62) (n 69)
>         (lena (- m (current-column)))   ; lena = m - (current-column)
>         (lenb (- n (current-column))) )
> 
>     (pcase count
>       (0
>          ;; makes s to be line with repeating ";"
>          (setq-local s (make-string lena ?\;))  ; repeats lena times
>        (insert-bifurcation s count)
>          (setq-local count 1))
>       (1
>          ;; makes s to be line with repeating ";"
>          (setq-local s (make-string lenb ?\;))  ; string length lenb
>        (insert-bifurcation s count)
>        (setq-local count 2))
>       (2
>          ;; makes s to be line with repeating "+"
>          (setq-local s (make-string lena ?+))
>        (insert-bifurcation s count)
>          (setq-local count 3))
>       (_
>          ;; deactivates the bifurcating line
>          (insert-bifurcation s count)
>          (setq-local count 1)) )) )
> 
> 
> 
> 
> 
> 
> > Sent: Wednesday, May 19, 2021 at 10:17 AM
> > From: "Jean Louis" <bugs@gnu.support>
> > To: michael-franzese@gmx.com
> > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" 
> > <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> > Subject: Re: Determining existence of text following point
> >
> > * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 23:52]:
> > > For instance, if the text in a commented string as follows, I will go 
> > > ahead with
> > > the insertion.
> > > 
> > (defun my-insert-on-empty-end-of-line (s)
> >   (let ((line-cut (buffer-substring-no-properties (point) 
> > (line-end-position))))
> >     (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp))
> >       (insert s))))
> > 
> > (defun my-insert-on-empty-end-of-line (s)
> >   (let ((line-cut (buffer-substring-no-properties (point) 
> > (line-end-position))))
> >     (when (or (not (string-match "[^+[:blank:];-]" line-cut)) (eolp))
> >       (insert s))))
> > 
> > (defun my-insert ()
> >   (interactive)
> >   (my-insert-on-empty-end-of-line "Hello"))
> > 
> > (local-set-key (kbd "<f5>") 'my-insert)
> > 
> > Line with blanks, works:
> > ;;          Hello                              
> > 
> > Line with something else but our series of chars (does not work, expected):
> > 
> > ;;       █               abc
> > 
> > Line with fancy stuff that we wish to include (works):
> > 
> > ;; ;;;;;;;;;;;;;;;;Hello;;;;;;;;;;;;;;;;;;;;;;
> > ;; +++++++++++++++++++++Hello+++++++++++++
> > ;; -------------------------Hello------Hello
> > 
> > Weird other lines (it does not work, as it is so expected):
> > 
> > ;; 𝓒𝓾𝓻𝓼𝓸𝓻 𝓲𝓼 𝓱𝓮𝓻𝓮: █  𝓫𝓾𝓽 𝓲𝓼 𝓷𝓸𝓽 𝔀𝓸𝓻𝓴𝓲𝓷𝓰, 𝐄𝐗𝐏𝐄𝐂𝐓𝐄𝐃!
> > 
> > 
> > -- 
> > Jean
> > 
> > Take action in Free Software Foundation campaigns:
> > https://www.fsf.org/campaigns
> > 
> > Sign an open letter in support of Richard M. Stallman
> > https://stallmansupport.org/
> > https://rms-support-letter.github.io/
> > 
> > 
> >
> 
>



reply via email to

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